diff --git a/Tests/images/unknown_compression_method.png b/Tests/images/unknown_compression_method.png new file mode 100644 index 000000000..e1614a731 Binary files /dev/null and b/Tests/images/unknown_compression_method.png differ diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index c51f56ce7..38ffc4bd0 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -619,6 +619,10 @@ class TestFilePng: with Image.open("Tests/images/hopper_idat_after_image_end.png") as im: assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"} + def test_unknown_compression_method(self) -> None: + with pytest.raises(SyntaxError, match="Unknown compression method"): + PngImagePlugin.PngImageFile("Tests/images/unknown_compression_method.png") + def test_padded_idat(self) -> None: # This image has been manually hexedited # so that the IDAT chunk has padding at the end diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 823f12492..d864fd201 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -392,8 +392,8 @@ class PngStream(ChunkStream): # Compressed profile n bytes (zlib with deflate compression) i = s.find(b"\0") logger.debug("iCCP profile name %r", s[:i]) - logger.debug("Compression method %s", s[i]) - comp_method = s[i] + comp_method = s[i + 1] + logger.debug("Compression method %s", comp_method) if comp_method != 0: msg = f"Unknown compression method {comp_method} in iCCP chunk" raise SyntaxError(msg)