mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Ensure PNG seeks to end of previous chunk at start of load_end
This commit is contained in:
parent
186145e5a0
commit
bf97a92bc6
BIN
Tests/images/padded_idat.png
Normal file
BIN
Tests/images/padded_idat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 B |
|
@ -628,6 +628,23 @@ class TestFilePng:
|
||||||
with Image.open("Tests/images/hopper_idat_after_image_end.png") as im:
|
with Image.open("Tests/images/hopper_idat_after_image_end.png") as im:
|
||||||
assert im.text == {"TXT": "VALUE", "ZIP": "VALUE"}
|
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):
|
def test_specify_bits(self, tmp_path):
|
||||||
im = hopper("P")
|
im = hopper("P")
|
||||||
|
|
||||||
|
|
|
@ -920,6 +920,8 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def load_end(self):
|
def load_end(self):
|
||||||
"""internal: finished reading image data"""
|
"""internal: finished reading image data"""
|
||||||
|
if self.__idat != 0:
|
||||||
|
self.fp.read(self.__idat)
|
||||||
while True:
|
while True:
|
||||||
self.fp.read(4) # CRC
|
self.fp.read(4) # CRC
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user