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

APK size increase because of empty file #1843

Closed
alexeikh opened this Issue Jul 18, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@alexeikh
Copy link
Contributor

alexeikh commented Jul 18, 2018

The problem

If an empty file exists in an APK - it causes no-compression for files with the same extension after rebuilding the APK. And, as a result, APK size increases, sometimes significantly, compared to the original APK.

This issue is a special case of issue #1572, which can be solved much easier than the whole #1572. #1572 is currently blocked by #1272, that has no planned fix.

Information

  1. Apktool Version - Snapshot from Git master from 2018-07-17 (2.3.4-eecfc1-SNAPSHOT).
  2. Operating System - Linux.
  3. APK From - Any APK with an empty file and non-empty file(s) with the same extension. For example, it is possible to take https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/test/resources/aapt1/unknown_compression/deflated_unknowns.apk and add the needed files there.

Steps to Reproduce

  1. Make an APK with an empty (zero-length) file and some (big) file with the same extension, for example into assets/ folder. Let's call these files empty.dat and big.dat. Don't try to avoid compression of the mentioned .dat files in the APK. Rather, try to add them compressed.
  2. List contents of the APK using unzip -v command.
    Observed: big.dat is added with DEFLATE compression method into the APK. For empty.dat the compression does not make sense, so it is added with STORE compression method into the APK.
  3. Rebuild the APK using apktool d and apktool b commands. Check the produced apktool.yml files.
    Observed: dat extension is added to the doNotCompress list.
    Expected: Should not be added just because of an empty file with the same extension.
  4. List contents of the rebuilt APK using unzip -v command.
    Observed: Both big.dat and empty.dat use STORE compression method in the rebuilt APK. The rebuilt APK size is significantly bigger than the original APK size.
    Expected: big.dat should still use DEFLATE method.

Suggested solution

Currently Apktool enforces non-compression for files with the same extension if at least one such file is stored non-compressed in the original APK. But, as mentioned above, "compression method" concept does not really make sense for zero-length files. Thus compression method should be ignored for zero-length files. Files should not be marked for non-compression just because there is an empty file with the same extension. The solution is thus to check that a file is not zero-length, before adding its extension to the doNotCompress list. Such solution should be easy to implement.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? - Yes.
  2. If you are trying to install a modified apk, did you resign it? - N/A.
  3. Are you using the latest apktool version? - Yes.
@alexeikh

This comment has been minimized.

Copy link
Contributor Author

alexeikh commented Jul 18, 2018

Uploading reproduce.zip, containing scripts for reproducing the issue.

Usage:

  1. Unpack reproduce.zip into some directory.
  2. Download https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/test/resources/aapt1/unknown_compression/deflated_unknowns.apk into the same directory.
  3. Copy the compiled Apktool "fat" JAR, apktool-cli-all.jar into the same directory.
  4. Run:
./reproduce.sh

reproduce.zip

@iBotPeaches

This comment has been minimized.

Copy link
Owner

iBotPeaches commented Jul 19, 2018

Confirmed. Thanks for detailed solution.

I believe best course of action is what you described, a check for zero-length size and if so, skip adding that file/extension to the doNotCompress list.

@iBotPeaches iBotPeaches self-assigned this Jul 19, 2018

@iBotPeaches iBotPeaches added this to the 2.4.0 milestone Jul 19, 2018

iBotPeaches added a commit that referenced this issue Jul 20, 2018

@iBotPeaches

This comment has been minimized.

Copy link
Owner

iBotPeaches commented Jul 20, 2018

Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.