python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

Handle rational tags with a zero denominator #8475

Closed radarhere closed 1 month ago

radarhere commented 1 month ago

Resolves #8471

When adding type hints in #8270, I added a cast to float.

https://github.com/python-pillow/Pillow/blob/11c654c187ffbede40c54e6344ddec49f495d4a7/src/PIL/TiffImagePlugin.py#L294-L297

However, that is causing a ZeroDivisionError when the value is an IFDRational with a denominator of zero.

I'm able to remove the cast without causing a mypy error, so I've reverted that specific change.

I created a test image with

im = Image.new("1", (1, 1))
exif = im.getexif()
exif[34853] = {
    2: (IFDRational(0, 0), IFDRational(0, 0), IFDRational(0, 0))
}
im.save("gpsinfo_zero_latitude.jpg", exif=exif)
radarhere commented 1 month ago

After fixing the type hint errors in #8474, the ZeroDivisionError starts occurring there.

So that PR can replace this one.