skip empty values in ImageFileDirectory

This commit is contained in:
homm 2016-07-12 18:09:02 +03:00
parent 4f4c982229
commit c2b4ff5fa4
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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'
'\x00\x00\x00\x00\x1b\x01\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x98\x82\x02\x00\x07\x00\x00\x002\x00\x00\x00\x00\x00\x00\x00a '
'text\x00\x00')
head = data.read(8)
info = TiffImagePlugin.ImageFileDirectory_v2(head)
info.load(data)
try:
info = info.as_dict()
except ValueError:
self.fail("Should not be struct value error there.")
self.assertIn(33432, info)
if __name__ == '__main__':
unittest.main()