From c2ada0cac8c304a00bf8d64c5dee3263bb06d1dd Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 17 Oct 2024 09:49:37 +1100 Subject: [PATCH] Handle rational tags with a zero denominator --- Tests/images/exif_gps_zero_denominator.jpg | Bin 0 -> 411 bytes Tests/test_file_jpeg.py | 4 ++++ src/PIL/TiffImagePlugin.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Tests/images/exif_gps_zero_denominator.jpg diff --git a/Tests/images/exif_gps_zero_denominator.jpg b/Tests/images/exif_gps_zero_denominator.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3db587f227dd11fb34a038de2b2148b79adce782 GIT binary patch literal 411 zcmex=&CY&d$ln!NnuO%frphBPk@zFCr@?FDEM{ zBcq_Ar>>x+qbwt%VXmoTU}$1uBCl>~Yhh%gXKZ5h{{RCw&=o*8G72*MKf)jnbO0-m z0|YR88JU<_SlQS)IJvli3bqO`FflSSGqEtUva$eO&R7eSXJ8Rz6;d>GWD^cdWLGK_ zF>0K+kVDyN<3Z7&iyu^slZu)+xx~aJB&Af<)HO7 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