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

fix crash when creating >2GB files on 32bit machine #189

Closed
wants to merge 4 commits into from

Conversation

hyh19962008
Copy link

@hyh19962008 hyh19962008 commented Sep 16, 2023

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().

size_t map_size = (size_t) lseek(fd, 0, SEEK_END);

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

AppImage/AppImageKit#1181

@hyh19962008 hyh19962008 changed the title allow max 4GB files to be created on 32bit machine fix crash when creating >2GB files on 32bit machine Sep 16, 2023
@hyh19962008
Copy link
Author

I was able to create files larger than 4GB now

@hyh19962008
Copy link
Author

hyh19962008 commented Oct 20, 2023

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.
appimagetool-i686-4GBpatched.appimage

Comment on lines +131 to +136
// 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;
Copy link
Member

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?

Copy link
Member

@TheAssassin TheAssassin left a 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
Copy link
Member

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...

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

Successfully merging this pull request may close these issues.

2 participants