Skip to content

Commit 3e852ee

Browse files
authored
Merge pull request #6431 from radarhere/png_srgb
Raise ValueError if PNG sRGB chunk is truncated
2 parents 4db2ed3 + 40a0999 commit 3e852ee

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Tests/test_file_png.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ def test_padded_idat(self):
635635

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

638-
@pytest.mark.parametrize("cid", (b"IHDR", b"pHYs", b"acTL", b"fcTL", b"fdAT"))
638+
@pytest.mark.parametrize(
639+
"cid", (b"IHDR", b"sRGB", b"pHYs", b"acTL", b"fcTL", b"fdAT")
640+
)
639641
def test_truncated_chunks(self, cid):
640642
fp = BytesIO()
641643
with PngImagePlugin.PngStream(fp) as png:

src/PIL/PngImagePlugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ def chunk_sRGB(self, pos, length):
509509
# 3 absolute colorimetric
510510

511511
s = ImageFile._safe_read(self.fp, length)
512+
if length < 1:
513+
if ImageFile.LOAD_TRUNCATED_IMAGES:
514+
return s
515+
raise ValueError("Truncated sRGB chunk")
512516
self.im_info["srgb"] = s[0]
513517
return s
514518

0 commit comments

Comments
 (0)