Ensure PNG seeks to end of previous chunk at start of load_end

This commit is contained in:
Andrew Murray 2021-05-14 13:18:49 +10:00
parent 186145e5a0
commit bf97a92bc6
3 changed files with 19 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

View File

@ -628,6 +628,23 @@ class TestFilePng:
with Image.open("Tests/images/hopper_idat_after_image_end.png") as im:
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}
def test_padded_idat(self):
# This image has been manually hexedited
# so that the IDAT chunk has padding at the end
# Set MAXBLOCK to the length of the actual data
# so that the decoder finishes reading before the chunk ends
MAXBLOCK = ImageFile.MAXBLOCK
ImageFile.MAXBLOCK = 45
ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open("Tests/images/padded_idat.png") as im:
im.load()
ImageFile.MAXBLOCK = MAXBLOCK
ImageFile.LOAD_TRUNCATED_IMAGES = False
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")
def test_specify_bits(self, tmp_path):
im = hopper("P")

View File

@ -920,6 +920,8 @@ class PngImageFile(ImageFile.ImageFile):
def load_end(self):
"""internal: finished reading image data"""
if self.__idat != 0:
self.fp.read(self.__idat)
while True:
self.fp.read(4) # CRC