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

Prevent shiftAmount overflow #9

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Prevent shiftAmount overflow #9

merged 1 commit into from
Feb 28, 2024

Conversation

klecko
Copy link
Contributor

@klecko klecko commented Feb 27, 2024

The variable shiftAmount is a short. Previously, it was a sum of values between 1 and alignment, which was usually 4. However, with .so aligning, it is now a sum between 1 and 4096, which is very easy to overflow, resulting in a corrupted ZIP file. I have attached a small zip with dummy .so files, that when zipaligned it results in an invalid ZIP file. I have also found this issue in real apks. Upgrading shiftAmount to an int solves the issue.

$ java -jar ./zipalign-java-1.1.1.jar ./test.zip ./test2.zip 
Aligning zip ./test.zip
Zip aligned successfully, took 6ms
$ unzip -t ./test2.zip
Archive:  ./test2.zip
error [./test2.zip]:  missing 4294901760 bytes in zipfile
  (attempting to process anyway)
error: invalid zip file with overlapped components (possible zip bomb)

@iyxan23
Copy link
Owner

iyxan23 commented Feb 28, 2024

🤦 thanks for the catch there. I will merge this shortly after.

What do you think of adding tests to prevent things like this? But, I don't feel like including test zip files into the repo would be a great idea, they'd make cloning slower.

@iyxan23 iyxan23 merged commit ca7ba91 into iyxan23:main Feb 28, 2024
1 check passed
@iyxan23
Copy link
Owner

iyxan23 commented Feb 28, 2024

Moved the above question to #10

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