diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index e0cb7528e..7f9bf7c1d 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -369,6 +369,10 @@ class TestFileJpeg(PillowTestCase): with self.assertRaises(IOError): im.load() + # Test that the error is raised if loaded a second time + with self.assertRaises(IOError): + im.load() + def _n_qtables_helper(self, n, test_file): im = Image.open(test_file) f = self.tempfile("temp.jpg") diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index f24f9deab..ceccd2285 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -111,6 +111,10 @@ class TestImageFile(PillowTestCase): with self.assertRaises(IOError): im.load() + # Test that the error is raised if loaded a second time + with self.assertRaises(IOError): + im.load() + def test_truncated_without_errors(self): if "zip_encoder" not in codecs: self.skipTest("PNG (zlib) encoder not available") diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 2b3d8e40a..836e6318c 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -244,7 +244,6 @@ class ImageFile(Image.Image): if LOAD_TRUNCATED_IMAGES: break else: - self.tile = [] raise IOError( "image file is truncated " "(%d bytes not processed)" % len(b) diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 658f5c04b..be237b3ee 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -612,7 +612,7 @@ class PngImageFile(ImageFile.ImageFile): rawmode, data = self.png.im_palette self.palette = ImagePalette.raw(rawmode, data) - self.__idat = length # used by load_read() + self.__prepare_idat = length # used by load_prepare() @property def text(self): @@ -645,6 +645,7 @@ class PngImageFile(ImageFile.ImageFile): if self.info.get("interlace"): self.decoderconfig = self.decoderconfig + (1,) + self.__idat = self.__prepare_idat # used by load_read() ImageFile.ImageFile.load_prepare(self) def load_read(self, read_bytes):