Merge pull request #6431 from radarhere/png_srgb

Raise ValueError if PNG sRGB chunk is truncated
This commit is contained in:
Hugo van Kemenade 2022-07-11 13:56:47 +03:00 committed by GitHub
commit 3e852eec93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -635,7 +635,9 @@ class TestFilePng:
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:

View File

@ -509,6 +509,10 @@ class PngStream(ChunkStream):
# 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