Skip to content

Commit

Permalink
Merge pull request #6431 from radarhere/png_srgb
Browse files Browse the repository at this point in the history
Raise ValueError if PNG sRGB chunk is truncated
  • Loading branch information
hugovk committed Jul 11, 2022
2 parents 4db2ed3 + 40a0999 commit 3e852ee
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
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
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 3e852ee

Please sign in to comment.