Skip to content

Commit

Permalink
Merge pull request #7458 from radarhere/truncated_exif
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Oct 13, 2023
2 parents 101154e + 7319d86 commit ff37a5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Binary file added Tests/images/truncated_exif_dpi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,13 @@ def test_dpi_exif_string(self):
# This should return the default
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):
# Arrange
# This is photoshop-200dpi.jpg with resolution removed from EXIF:
Expand Down
14 changes: 11 additions & 3 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,19 @@ def APP(self, marker):
# 1 dpcm = 2.54 dpi
dpi *= 2.54
self.info["dpi"] = dpi, dpi
except (TypeError, KeyError, SyntaxError, ValueError, ZeroDivisionError):
# SyntaxError for invalid/unreadable EXIF
except (
struct.error,
KeyError,
SyntaxError,
TypeError,
ValueError,
ZeroDivisionError,
):
# struct.error for truncated EXIF
# 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
# ZeroDivisionError for invalid dpi rational value
self.info["dpi"] = 72, 72


Expand Down

0 comments on commit ff37a5b

Please sign in to comment.