diff --git a/Tests/images/corrupt_exif.jpg b/Tests/images/corrupt_exif.jpg new file mode 100644 index 000000000..12767e13f Binary files /dev/null and b/Tests/images/corrupt_exif.jpg differ diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index e0cb7528e..7a48a460c 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -633,6 +633,11 @@ class TestFileJpeg(PillowTestCase): # Act / Assert self.assertEqual(im._getexif()[306], "2017:03:13 23:03:09") + def test_bad_exif_overflow_32(self): + # This image has some corrupt exif offsets that unpack to values greater + # than ssize_t on 32 bit systems + im = Image.open('Tests/images/corrupt_exif.jpg') + def test_photoshop(self): im = Image.open("Tests/images/photoshop-200dpi.jpg") self.assertEqual( diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index d6361bfc5..37b75886e 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -776,7 +776,7 @@ class ImageFileDirectory_v2(MutableMapping): except OverflowError as e: if DEBUG: print( - "- offset value wrong. Possibly corrupt EXIF data. ", e + "Offset too large. Possibly corrupt EXIF data. ", e ) continue # ignore corrupt EXIF data data = ImageFile._safe_read(fp, size)