ianare / exif-py

Easy to use Python module to extract Exif metadata from digital image files.
BSD 3-Clause "New" or "Revised" License
831 stars 191 forks source link

Bug in function Ratio.decimal (probably very easy to fix ZeroDivisionError) #192

Open AnthonyZi opened 7 months ago

AnthonyZi commented 7 months ago

First of all thank you very much for this great Project helping me to extract meta data from photos!

Using exifread for reading the GPS data from images and I ran into an unexpected exception calling the "decimal" function of a Rational object and adding rationals with the addition ("+") operator.

The following three lines in an interactive python shell can be used to reproduce the error:

>>> import exifread
>>> exifread.utils.Ratio(0, 0) + 1  # -> ZeroDivisionError
>>> exifread.utils.Ratio(0, 0).decimal()  # -> ZeroDivisionError

How severe is this issue? The photos taken with my ordinary smartphone have some exif data for GPS coordinates stored that I read with exifread yielding exactly the "0/0" Rational issue:

>>> gps_longitude, gps_latitude, gps_altitude = get_exif_gps_coordinates()
>>> print(f"{gps_longitude}, {type(gps_longitude)}")
>>> 0/0 <class 'exifread.utils.Ratio'>
>>> print(f"{gps_latitude}, {type(gps_latitude)}")
>>> 0/0 <class 'exifread.utils.Ratio'>
>>> print(f"{gps_altitude}, {type(gps_altitude)}")
>>> 0/0 <class 'exifread.utils.Ratio'>

Bug fix brainstorming ideas ( Idid not really think through any of this ideas in depth):