fix tiff exif loading in case when file is empty or ended

This commit is contained in:
homm 2015-09-15 04:06:51 +03:00
parent 63f5f68837
commit 9930b05a33
2 changed files with 13 additions and 1 deletions

View File

@ -428,7 +428,7 @@ def _getexif(self):
# exif field 0x8825 is an offset pointer to the location # exif field 0x8825 is an offset pointer to the location
# of the nested embedded gps exif ifd. # of the nested embedded gps exif ifd.
# It should be a long, but may be corrupted. # It should be a long, but may be corrupted.
file.seek(exif[0x8825]) file.seek(exif[0x8825])
except (KeyError, TypeError): except (KeyError, TypeError):
pass pass
else: else:

View File

@ -1,5 +1,8 @@
from __future__ import division from __future__ import division
import io
import struct
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin, TiffTags from PIL import Image, TiffImagePlugin, TiffTags
@ -136,6 +139,15 @@ class TestFileTiffMetadata(PillowTestCase):
self.assertEqual(tag_ids['MakerNoteSafety'], 50741) self.assertEqual(tag_ids['MakerNoteSafety'], 50741)
self.assertEqual(tag_ids['BestQualityScale'], 50780) self.assertEqual(tag_ids['BestQualityScale'], 50780)
def test_empty_metadata(self):
f = io.BytesIO(b'II*\x00\x08\x00\x00\x00')
head = f.read(8)
info = TiffImagePlugin.ImageFileDirectory(head)
try:
self.assert_warning(UserWarning, lambda: info.load(f))
except struct.error:
self.fail("Should not be struct errors there.")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()