mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-25 00:34:14 +03:00
Merge pull request #7458 from radarhere/truncated_exif
This commit is contained in:
commit
ff37a5be37
BIN
Tests/images/truncated_exif_dpi.jpg
Normal file
BIN
Tests/images/truncated_exif_dpi.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
|
@ -767,6 +767,13 @@ class TestFileJpeg:
|
||||||
# This should return the default
|
# This should return the default
|
||||||
assert im.info.get("dpi") == (72, 72)
|
assert im.info.get("dpi") == (72, 72)
|
||||||
|
|
||||||
|
def test_dpi_exif_truncated(self):
|
||||||
|
# Arrange
|
||||||
|
with Image.open("Tests/images/truncated_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):
|
def test_no_dpi_in_exif(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
|
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
|
||||||
|
|
|
@ -170,11 +170,19 @@ def APP(self, marker):
|
||||||
# 1 dpcm = 2.54 dpi
|
# 1 dpcm = 2.54 dpi
|
||||||
dpi *= 2.54
|
dpi *= 2.54
|
||||||
self.info["dpi"] = dpi, dpi
|
self.info["dpi"] = dpi, dpi
|
||||||
except (TypeError, KeyError, SyntaxError, ValueError, ZeroDivisionError):
|
except (
|
||||||
# SyntaxError for invalid/unreadable EXIF
|
struct.error,
|
||||||
|
KeyError,
|
||||||
|
SyntaxError,
|
||||||
|
TypeError,
|
||||||
|
ValueError,
|
||||||
|
ZeroDivisionError,
|
||||||
|
):
|
||||||
|
# struct.error for truncated EXIF
|
||||||
# KeyError for dpi not included
|
# KeyError for dpi not included
|
||||||
# ZeroDivisionError for invalid dpi rational value
|
# SyntaxError for invalid/unreadable EXIF
|
||||||
# ValueError or TypeError for dpi being an invalid float
|
# ValueError or TypeError for dpi being an invalid float
|
||||||
|
# ZeroDivisionError for invalid dpi rational value
|
||||||
self.info["dpi"] = 72, 72
|
self.info["dpi"] = 72, 72
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user