diff --git a/Tests/images/hopper_idat_after_image_end.png b/Tests/images/hopper_idat_after_image_end.png new file mode 100644 index 000000000..70b4a6400 Binary files /dev/null and b/Tests/images/hopper_idat_after_image_end.png differ diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 408a76444..c94f8eaad 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -586,6 +586,10 @@ class TestFilePng(PillowTestCase): self.assertIsInstance(im.text, dict) ImageFile.LOAD_TRUNCATED_IMAGES = False + # Raises an EOFError in load_end + im = Image.open("Tests/images/hopper_idat_after_image_end.png") + self.assertEqual(im.text, {'TXT': 'VALUE', 'ZIP': 'VALUE'}) + @unittest.skipUnless(HAVE_WEBP and _webp.HAVE_WEBPANIM, "WebP support not installed with animation") def test_apng(self): diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index d8ef56d73..f3a2eaf21 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -680,6 +680,8 @@ class PngImageFile(ImageFile.ImageFile): self.png.call(cid, pos, length) except UnicodeDecodeError: break + except EOFError: + ImageFile._safe_read(self.fp, length) self._text = self.png.im_text self.png.close() self.png = None