Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise the same error if a truncated image is loaded a second time #3965

Merged
merged 1 commit into from Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/test_file_jpeg.py
Expand Up @@ -372,6 +372,10 @@ def test_truncated_jpeg_throws_IOError(self):
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")
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_imagefile.py
Expand Up @@ -113,6 +113,10 @@ def test_truncated_with_errors(self):
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")
Expand Down
1 change: 0 additions & 1 deletion src/PIL/ImageFile.py
Expand Up @@ -243,7 +243,6 @@ def load(self):
if LOAD_TRUNCATED_IMAGES:
break
else:
self.tile = []
raise IOError(
"image file is truncated "
"(%d bytes not processed)" % len(b)
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/PngImagePlugin.py
Expand Up @@ -612,7 +612,7 @@ def _open(self):
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):
Expand Down Expand Up @@ -645,6 +645,7 @@ def load_prepare(self):
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):
Expand Down