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 be52b3bd1..5f0113070 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -585,6 +585,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 04161a56c..42c570668 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -677,6 +677,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