Merge pull request #1414 from wiredfool/pr1360

Catch TypeError in _getexif
This commit is contained in:
Hugo van Kemenade 2015-09-10 19:11:32 +03:00
commit 991829b75a
4 changed files with 20 additions and 3 deletions

View File

@ -422,8 +422,11 @@ def _getexif(self):
exif[key] = _fixup(value)
# get exif extension
try:
# exif field 0x8769 is an offset pointer to the location
# of the nested embedded exif ifd.
# It should be a long, but may be corrupted.
file.seek(exif[0x8769])
except KeyError:
except (KeyError, TypeError):
pass
else:
info = TiffImagePlugin.ImageFileDirectory(head)
@ -432,8 +435,11 @@ def _getexif(self):
exif[key] = _fixup(value)
# get gpsinfo extension
try:
file.seek(exif[0x8825])
except KeyError:
# exif field 0x8825 is an offset pointer to the location
# of the nested embedded gps exif ifd.
# It should be a long, but may be corrupted.
file.seek(exif[0x8825])
except (KeyError, TypeError):
pass
else:
info = TiffImagePlugin.ImageFileDirectory(head)

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -166,6 +166,17 @@ class TestFileJpeg(PillowTestCase):
im = hopper()
im.save(f, 'JPEG', quality=90, exif=b"1"*65532)
def test_exif_typeerror(self):
im = Image.open('Tests/images/exif_typeerror.jpg')
# Should not raise a TypeError
im._getexif()
def test_exif_gps_typeerror(self):
im = Image.open('Tests/images/exif_gps_typeerror.jpg')
# Should not raise a TypeError
im._getexif()
def test_progressive_compat(self):
im1 = self.roundtrip(hopper())
im2 = self.roundtrip(hopper(), progressive=1)