pexif
pexif copied to clipboard
Integer overflow when setting coordinates with set_geo
Hello! I have the following error while writing image with new coordinates which have been set by set_geo function:
File "/usr/local/lib/python2.7/dist-packages/pexif.py", line 520, in getdata actual_data += pack(e + t, *the_data[i].as_tuple()) error: 'i' format requires -2147483648 <= number <= 2147483647
I debug the code a little and saw that if we have here
secs = long(secs * JpegFile.SEC_DEN)
seconds more than 42,94967294 we have such an error.
So, why do you need to multiply seconds to JpegFile.SEC_DEN = 50000000 at all?
Thanks!
I got a related problem setting GPS coordinates via pexif and looking at them via Exiv2 or other software which use the libexiv2 library: if the numerator of the rational expressing the seconds of latitude or longitude is greather than (2^32)/2, it triggers an overflow in libexiv2, thus showing the number as negative. So I opened an issue on Exiv2. May be it is so crazy that pexif uses a so huge denominator (50000000), which is rather an overkill for the precision of seconds of lat/lon. Changing that value with something lower than 35791394, will avoid the overflow.
I solved this problem for me with setting SEC_DEN to 5000 before calling set_geo:
pexif.JpegFile.SEC_DEN = 5000
img.set_geo(gps_data['lat'], gps_data['lon'])