mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 01:43:17 +03:00
Merge pull request #1428 from uploadcare/load-broken-images
Load more broken images
This commit is contained in:
commit
388b2dab0c
|
@ -190,9 +190,6 @@ class ImageFile(Image.Image):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
prefix = b""
|
prefix = b""
|
||||||
|
|
||||||
# Buffer length read; assign a default value
|
|
||||||
t = 0
|
|
||||||
|
|
||||||
for d, e, o, a in self.tile:
|
for d, e, o, a in self.tile:
|
||||||
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
|
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
|
||||||
seek(o)
|
seek(o)
|
||||||
|
@ -201,7 +198,6 @@ class ImageFile(Image.Image):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
b = prefix
|
b = prefix
|
||||||
t = len(b)
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
s = read(self.decodermaxblock)
|
s = read(self.decodermaxblock)
|
||||||
|
@ -230,7 +226,6 @@ class ImageFile(Image.Image):
|
||||||
if n < 0:
|
if n < 0:
|
||||||
break
|
break
|
||||||
b = b[n:]
|
b = b[n:]
|
||||||
t = t + n
|
|
||||||
# Need to cleanup here to prevent leaks in PyPy
|
# Need to cleanup here to prevent leaks in PyPy
|
||||||
d.cleanup()
|
d.cleanup()
|
||||||
|
|
||||||
|
@ -239,7 +234,7 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
self.fp = None # might be shared
|
self.fp = None # might be shared
|
||||||
|
|
||||||
if not self.map and (not LOAD_TRUNCATED_IMAGES or t == 0) and e < 0:
|
if not self.map and not LOAD_TRUNCATED_IMAGES and e < 0:
|
||||||
# still raised if decoder fails to return anything
|
# still raised if decoder fails to return anything
|
||||||
raise_ioerror(e)
|
raise_ioerror(e)
|
||||||
|
|
||||||
|
|
BIN
Tests/images/broken_data_stream.png
Normal file
BIN
Tests/images/broken_data_stream.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -115,6 +115,26 @@ class TestImageFile(PillowTestCase):
|
||||||
finally:
|
finally:
|
||||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
|
|
||||||
|
def test_broken_datastream_with_errors(self):
|
||||||
|
if "zip_encoder" not in codecs:
|
||||||
|
self.skipTest("PNG (zlib) encoder not available")
|
||||||
|
|
||||||
|
im = Image.open("Tests/images/broken_data_stream.png")
|
||||||
|
with self.assertRaises(IOError):
|
||||||
|
im.load()
|
||||||
|
|
||||||
|
def test_broken_datastream_without_errors(self):
|
||||||
|
if "zip_encoder" not in codecs:
|
||||||
|
self.skipTest("PNG (zlib) encoder not available")
|
||||||
|
|
||||||
|
im = Image.open("Tests/images/broken_data_stream.png")
|
||||||
|
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
try:
|
||||||
|
im.load()
|
||||||
|
finally:
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user