Handle broken Photoshop data

This commit is contained in:
Andrew Murray 2019-11-30 10:08:32 +11:00
parent a9fc1b66b1
commit e51be50549
3 changed files with 9 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -656,6 +656,11 @@ class TestFileJpeg(PillowTestCase):
},
)
# Test that the image can still load, even with broken Photoshop data
# This image had the APP13 length hexedited to be smaller
with Image.open("Tests/images/photoshop-200dpi-broken.jpg") as im_broken:
self.assert_image_equal(im_broken, im)
# This image does not contain a Photoshop header string
with Image.open("Tests/images/app13.jpg") as im:
self.assertNotIn("photoshop", im.info)

View File

@ -109,7 +109,10 @@ def APP(self, marker):
while blocks[offset : offset + 4] == b"8BIM":
offset += 4
# resource code
code = i16(blocks, offset)
try:
code = i16(blocks, offset)
except struct.error:
break
offset += 2
# resource name (usually empty)
name_len = i8(blocks[offset])