mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Fix ZeroDivisionError when EXIF contains invalid DPI (0/0).
This commit is contained in:
parent
cae7789372
commit
7c8e0e4457
|
@ -131,9 +131,10 @@ def APP(self, marker):
|
|||
# 1 dpcm = 2.54 dpi
|
||||
dpi *= 2.54
|
||||
self.info["dpi"] = dpi, dpi
|
||||
except (KeyError, SyntaxError):
|
||||
except (KeyError, SyntaxError, ZeroDivisionError):
|
||||
# SyntaxError for invalid/unreadable exif
|
||||
# KeyError for dpi not included
|
||||
# ZeroDivisionError for invalid dpi rational value
|
||||
self.info["dpi"] = 72, 72
|
||||
|
||||
|
||||
|
|
BIN
Tests/images/exif-dpi-zerodivision.jpg
Normal file
BIN
Tests/images/exif-dpi-zerodivision.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -535,6 +535,16 @@ class TestFileJpeg(PillowTestCase):
|
|||
# Act / Assert
|
||||
self.assertEqual(im.info.get("dpi"), (508, 508))
|
||||
|
||||
def test_dpi_exif_zero_division(self):
|
||||
# Arrange
|
||||
# This is photoshop-200dpi.jpg with EXIF resolution set to 0/0:
|
||||
# exiftool -XResolution=0/0 -YResolution=0/0 photoshop-200dpi.jpg
|
||||
im = Image.open("Tests/images/exif-dpi-zerodivision.jpg")
|
||||
|
||||
# Act / Assert
|
||||
# This should return the default, and not raise a ZeroDivisionError
|
||||
self.assertEqual(im.info.get("dpi"), (72, 72))
|
||||
|
||||
def test_no_dpi_in_exif(self):
|
||||
# Arrange
|
||||
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
|
||||
|
|
Loading…
Reference in New Issue
Block a user