mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 14:54:46 +03:00
prevent div by zero for exif rationals with zero denominator
This commit is contained in:
parent
b7501aa3c0
commit
7dbf0209e3
|
@ -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]))
|
||||
|
||||
|
|
BIN
Tests/images/exif_zerodivisionerror.jpg
Normal file
BIN
Tests/images/exif_zerodivisionerror.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user