Merge pull request #1 from radarhere/exif-writing-fixes

Corrected short and long range checks
This commit is contained in:
Konstantin Kopachev 2019-08-29 09:06:28 -07:00 committed by GitHub
commit 47513c5430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -274,6 +274,18 @@ class TestFileTiffMetadata(PillowTestCase):
self.assertEqual(numerator, reloaded.tag_v2[37380].numerator)
self.assertEqual(denominator, reloaded.tag_v2[37380].denominator)
def test_ifd_signed_long(self):
im = hopper()
info = TiffImagePlugin.ImageFileDirectory_v2()
info[37000] = -60000
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(reloaded.tag_v2[37000], -60000)
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"

View File

@ -575,12 +575,10 @@ class ImageFileDirectory_v2(MutableMapping):
else TiffTags.SIGNED_RATIONAL
)
elif all(isinstance(v, int) for v in values):
if all(v < 2 ** 16 for v in values):
self.tagtype[tag] = (
TiffTags.SHORT
if all(v >= 0 for v in values)
else TiffTags.SIGNED_SHORT
)
if all(0 <= v < 2 ** 16 for v in values):
self.tagtype[tag] = TiffTags.SHORT
elif all(-2 ** 15 < v < 2 ** 15 for v in values):
self.tagtype[tag] = TiffTags.SIGNED_SHORT
else:
self.tagtype[tag] = (
TiffTags.LONG