mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Merge pull request #2024 from uploadcare/fix-empty-exif-tags
Skip empty values in ImageFileDirectory
This commit is contained in:
commit
4a90e8f75b
|
@ -701,6 +701,9 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
"Skipping tag %s" % (size, len(data), tag))
|
||||
continue
|
||||
|
||||
if not data:
|
||||
continue
|
||||
|
||||
self._tagdata[tag] = data
|
||||
self.tagtype[tag] = typ
|
||||
|
||||
|
|
|
@ -263,6 +263,8 @@ class TestFileTiff(PillowTestCase):
|
|||
|
||||
self.assert_warning(DeprecationWarning, im.tag_v2.as_dict)
|
||||
self.assert_warning(DeprecationWarning, im.tag.as_dict)
|
||||
self.assertEqual(dict(im.tag_v2), im.tag_v2.as_dict())
|
||||
self.assertEqual(dict(im.tag), im.tag.as_dict())
|
||||
|
||||
def test_dict(self):
|
||||
# Arrange
|
||||
|
@ -274,7 +276,6 @@ class TestFileTiff(PillowTestCase):
|
|||
262: 2, 296: 2, 273: (8,), 338: (1,), 277: 4,
|
||||
279: (9460,), 282: 72.0, 283: 72.0, 284: 1}
|
||||
self.assertEqual(dict(im.tag_v2), v2_tags)
|
||||
self.assertEqual(im.tag_v2.as_dict(), v2_tags)
|
||||
|
||||
# legacy interface
|
||||
legacy_tags = {256: (55,), 257: (43,), 258: (8, 8, 8, 8), 259: (1,),
|
||||
|
@ -282,7 +283,6 @@ class TestFileTiff(PillowTestCase):
|
|||
279: (9460,), 282: ((720000, 10000),),
|
||||
283: ((720000, 10000),), 284: (1,)}
|
||||
self.assertEqual(dict(im.tag), legacy_tags)
|
||||
self.assertEqual(im.tag.as_dict(), legacy_tags)
|
||||
|
||||
def test__delitem__(self):
|
||||
filename = "Tests/images/pil136.tiff"
|
||||
|
|
|
@ -208,6 +208,21 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
self.assertEqual(0, reloaded.tag_v2[41988][0].numerator)
|
||||
self.assertEqual(0, reloaded.tag_v2[41988][0].denominator)
|
||||
|
||||
def test_expty_values(self):
|
||||
data = io.BytesIO(
|
||||
b'II*\x00\x08\x00\x00\x00\x03\x00\x1a\x01\x05\x00\x00\x00\x00\x00'
|
||||
b'\x00\x00\x00\x00\x1b\x01\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||
b'\x98\x82\x02\x00\x07\x00\x00\x002\x00\x00\x00\x00\x00\x00\x00a '
|
||||
b'text\x00\x00')
|
||||
head = data.read(8)
|
||||
info = TiffImagePlugin.ImageFileDirectory_v2(head)
|
||||
info.load(data)
|
||||
try:
|
||||
info = dict(info)
|
||||
except ValueError:
|
||||
self.fail("Should not be struct value error there.")
|
||||
self.assertIn(33432, info)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user