Skip to content

Commit

Permalink
Handle rational tags with a zero denominator
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 16, 2024
1 parent 11c654c commit c2ada0c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Binary file added Tests/images/exif_gps_zero_denominator.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ def test_exif_gps_typeerror(self) -> None:
# Should not raise a TypeError
im._getexif()

def test_exif_gps_zero_denominator(self) -> None:
with Image.open("Tests/images/exif_gps_zero_denominator.jpg") as im:
im.getexif().tobytes()

def test_progressive_compat(self) -> None:
im1 = self.roundtrip(hopper())
assert not im1.info.get("progressive")
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _accept(prefix: bytes) -> bool:
def _limit_rational(
val: float | Fraction | IFDRational, max_val: int
) -> tuple[IntegralLike, IntegralLike]:
inv = abs(float(val)) > 1
inv = abs(val) > 1
n_d = IFDRational(1 / val if inv else val).limit_rational(max_val)
return n_d[::-1] if inv else n_d

Expand Down

0 comments on commit c2ada0c

Please sign in to comment.