Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer overflow when setting coordinates with set_geo #28

Open
kpetrykin opened this issue Apr 9, 2018 · 2 comments
Open

Integer overflow when setting coordinates with set_geo #28

kpetrykin opened this issue Apr 9, 2018 · 2 comments

Comments

@kpetrykin
Copy link

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!

@RigacciOrg
Copy link

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.

@kpetrykin
Copy link
Author

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'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants