Skip to content

Commit 6dedf61

Browse files
committed
Pleasing black
1 parent 43d341c commit 6dedf61

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

fpdf/fpdf.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2732,11 +2732,15 @@ def image(
27322732
if isinstance(name, str):
27332733
img = None
27342734
elif isinstance(name, Image.Image):
2735-
name, img = hashlib.md5(name.tobytes()).hexdigest(), name # nosec B303,B324 # we just build a cache key, this is secure
2735+
bytes = name.tobytes()
2736+
# disabling bandit rule as we just build a cache key, this is secure
2737+
name, img = hashlib.md5(bytes).hexdigest(), name # nosec B303 B324
27362738
elif isinstance(name, io.BytesIO):
27372739
if _is_xml(name):
27382740
return self._vector_image(name, x, y, w, h, link, title, alt_text)
2739-
name, img = hashlib.md5(name.getvalue()).hexdigest(), name # nosec B303,B324 # we just build a cache key, this is secure
2741+
bytes = name.getvalue()
2742+
# disabling bandit rule as we just build a cache key, this is secure
2743+
name, img = hashlib.md5(bytes).hexdigest(), name # nosec B303 B324
27402744
else:
27412745
name, img = str(name), name
27422746
info = self.images.get(name)

fpdf/image_parsing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def load_image(filename):
2222
return filename
2323
# by default loading from network is allowed for all images
2424
if filename.startswith(("http://", "https://")):
25-
with urlopen(filename) as url_file: # nosec B310 # permitted schemes are whitelisted
25+
# disabling bandit rule as permitted schemes are whitelisted:
26+
with urlopen(filename) as url_file: # nosec B310
2627
return BytesIO(url_file.read())
2728
elif filename.startswith("data"):
2829
return _decode_base64_image(filename)

test/image/test_vector_image.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_svg_image_from_bytesio(tmp_path):
6060

6161

6262
def test_svg_image_billion_laughs():
63+
"cf. https://pypi.org/project/defusedxml/#attack-vectors"
6364
pdf = fpdf.FPDF()
6465
pdf.add_page()
6566
with pytest.raises(EntitiesForbidden):

0 commit comments

Comments
 (0)