Handle rational tags with a zero denominator

This commit is contained in:
Andrew Murray 2024-10-17 09:49:37 +11:00
parent 11c654c187
commit c2ada0cac8
3 changed files with 5 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

View File

@ -406,6 +406,10 @@ class TestFileJpeg:
# 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")

View File

@ -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