Skip to content

Commit

Permalink
Raise ValueError if PNG sRGB chunk is truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 11, 2022
1 parent 4db2ed3 commit 40a0999
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ def test_padded_idat(self):

assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")

@pytest.mark.parametrize("cid", (b"IHDR", b"pHYs", b"acTL", b"fcTL", b"fdAT"))
@pytest.mark.parametrize(
"cid", (b"IHDR", b"sRGB", b"pHYs", b"acTL", b"fcTL", b"fdAT")
)
def test_truncated_chunks(self, cid):
fp = BytesIO()
with PngImagePlugin.PngStream(fp) as png:
Expand Down
4 changes: 4 additions & 0 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ def chunk_sRGB(self, pos, length):
# 3 absolute colorimetric

s = ImageFile._safe_read(self.fp, length)
if length < 1:
if ImageFile.LOAD_TRUNCATED_IMAGES:
return s
raise ValueError("Truncated sRGB chunk")
self.im_info["srgb"] = s[0]
return s

Expand Down

0 comments on commit 40a0999

Please sign in to comment.