mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #5639 from uploadcare/jpeg-safe-dpi-read
Add TypeError handling to pass corrupted DPI value in EXIF
This commit is contained in:
commit
a312b0e9d0
BIN
Tests/images/broken_exif_dpi.jpg
Normal file
BIN
Tests/images/broken_exif_dpi.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
|
@ -718,6 +718,15 @@ class TestFileJpeg:
|
|||
# This should return the default, and not raise a ZeroDivisionError
|
||||
assert im.info.get("dpi") == (72, 72)
|
||||
|
||||
def test_dpi_exif_string(self):
|
||||
# Arrange
|
||||
# 0x011A tag in this exif contains string '300300\x02'
|
||||
with Image.open("Tests/images/broken_exif_dpi.jpg") as im:
|
||||
|
||||
# Act / Assert
|
||||
# This should return the default
|
||||
assert im.info.get("dpi") == (72, 72)
|
||||
|
||||
def test_no_dpi_in_exif(self):
|
||||
# Arrange
|
||||
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
|
||||
|
|
|
@ -168,11 +168,11 @@ def APP(self, marker):
|
|||
# 1 dpcm = 2.54 dpi
|
||||
dpi *= 2.54
|
||||
self.info["dpi"] = dpi, dpi
|
||||
except (KeyError, SyntaxError, ValueError, ZeroDivisionError):
|
||||
except (TypeError, KeyError, SyntaxError, ValueError, ZeroDivisionError):
|
||||
# SyntaxError for invalid/unreadable EXIF
|
||||
# KeyError for dpi not included
|
||||
# ZeroDivisionError for invalid dpi rational value
|
||||
# ValueError for dpi being an invalid float
|
||||
# ValueError or TypeError for dpi being an invalid float
|
||||
self.info["dpi"] = 72, 72
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user