-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix crash when creating >2GB files on 32bit machine #189
Conversation
I was able to create files larger than 4GB now |
I made a build on Ubuntu 16.04(Xenial) for testing, it only works well on native 32bit system. Running it on a 64bit system still gets the same problem. |
// prevent map_size wrap around on 32bit platform | ||
// we only need to read section header table, this should be big enough | ||
if (sizeof(long) == 4 && file_size > UINT_MAX) | ||
map_size = INT_MAX; | ||
else | ||
map_size = (size_t)file_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just always use UINT_MAX
, couldn't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. However, it doesn't work the way you think. I'll open my own version soon.
@@ -1,3 +1,4 @@ | |||
#define _FILE_OFFSET_BITS 64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While doing some research on the topic anyway for zsync2/AppImageUpdate (which use libgpgme which in turn uses 64-bit types for file sizes apparently), I found that this is not the right way. You should set it as a compiler definition. Then, you can skip the detection logic and mmap
/open
work as expected.
In theory, we could also just hardcode UINT_MAX
...
appimagetool will crash on appimage_get_elf_section_offset_and_length() when creating file larger than 2GB on 32bit machine, because in this line lssek() returns -1 and errno set to EOVERFLOW. map_size with value UINT_MAX(-1) is then passed to mmap().
Adding "#define _FILE_OFFSET_BITS 64" will change off_t to 64bit, then we can get the correct file size from lseek.
related issues:
#21