diff --git a/Tests/images/exif_gps_zero_denominator.jpg b/Tests/images/exif_gps_zero_denominator.jpg new file mode 100644 index 000000000..3db587f22 Binary files /dev/null and b/Tests/images/exif_gps_zero_denominator.jpg differ diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index cde951395..e75a662a8 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -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") diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index ff5a6f9e9..bc7d3a84d 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -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