mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Fix png image plugin load_end func handle truncated file.
This commit is contained in:
parent
067c5f4123
commit
44e77a22b5
BIN
Tests/images/end_trunc_file.png
Normal file
BIN
Tests/images/end_trunc_file.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -777,6 +777,15 @@ class TestFilePng:
|
||||||
mystdout = mystdout.buffer
|
mystdout = mystdout.buffer
|
||||||
with Image.open(mystdout) as reloaded:
|
with Image.open(mystdout) as reloaded:
|
||||||
assert_image_equal_tofile(reloaded, TEST_PNG_FILE)
|
assert_image_equal_tofile(reloaded, TEST_PNG_FILE)
|
||||||
|
|
||||||
|
def test_end_truncated_file(self):
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
|
try:
|
||||||
|
with Image.open("Tests/images/end_trunc_file.png") as im:
|
||||||
|
assert_image_equal_tofile(im, "Tests/images/end_trunc_file.png")
|
||||||
|
finally:
|
||||||
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS")
|
@pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS")
|
||||||
|
|
|
@ -981,7 +981,13 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
if cid == b"fdAT":
|
if cid == b"fdAT":
|
||||||
length -= 4
|
length -= 4
|
||||||
ImageFile._safe_read(self.fp, length)
|
try:
|
||||||
|
ImageFile._safe_read(self.fp, length)
|
||||||
|
except OSError as e:
|
||||||
|
if ImageFile.LOAD_TRUNCATED_IMAGES:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logger.debug("%r %s %s (unknown)", cid, pos, length)
|
logger.debug("%r %s %s (unknown)", cid, pos, length)
|
||||||
s = ImageFile._safe_read(self.fp, length)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user