prevent div by zero for exif rationals with zero denominator

This commit is contained in:
kraiz 2015-10-12 20:24:33 +02:00
parent b7501aa3c0
commit 7dbf0209e3
3 changed files with 9 additions and 1 deletions

View File

@ -208,6 +208,8 @@ OPEN_INFO = {
PREFIXES = [b"MM\000\052", b"II\052\000", b"II\xBC\000"]
FLOAT_MIN = sys.float_info.min * sys.float_info.epsilon
def _accept(prefix):
return prefix[:4] in PREFIXES
@ -477,7 +479,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
@_register_loader(5, 8)
def load_rational(self, data, legacy_api=True):
vals = self._unpack("{0}L".format(len(data) // 4), data)
combine = lambda a, b: (a, b) if legacy_api else a / b
combine = lambda a, b: (a, b) if legacy_api else a / (b or FLOAT_MIN)
return tuple(combine(num, denom)
for num, denom in zip(vals[::2], vals[1::2]))

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -177,6 +177,12 @@ class TestFileJpeg(PillowTestCase):
# Should not raise a TypeError
im._getexif()
def test_exif_zerodivisionerror(self):
im = Image.open('Tests/images/exif_zerodivisionerror.jpg')
# Should not raise a ZeroDivisionError
im._getexif()
def test_progressive_compat(self):
im1 = self.roundtrip(hopper())
im2 = self.roundtrip(hopper(), progressive=1)