[BUG] invalid CEN header (bad compression method)
Information
-
Apktool Version (
apktool -version) - Apktool 2.12.0 - Operating System (Mac, Linux, Windows) - Mac
- APK From? (Playstore, ROM, Other) - I was sent this file in telegram, and I became interested in understanding it. I think this file contains a virus
-
Java Version (
java --version) - openjdk 21.0.7 2025-04-15 OpenJDK Runtime Environment Homebrew (build 21.0.7) OpenJDK 64-Bit Server VM Homebrew (build 21.0.7, mixed mode, sharing)
Stacktrace/Logcat
java -jar apktool.jar d app.apk -o app_src -f
I: Using Apktool 2.12.0 on app.apk with 8 threads
Exception in thread "main" brut.androlib.exceptions.AndrolibException: brut.directory.DirectoryException: java.util.zip.ZipException: invalid CEN header (bad compression method: 27639)
at brut.androlib.ApkDecoder.decodeSources(SourceFile:271)
at brut.androlib.ApkDecoder.decode(SourceFile:83)
at brut.apktool.Main.main(SourceFile:524)
Caused by: brut.directory.DirectoryException: java.util.zip.ZipException: invalid CEN header (bad compression method: 27639)
at brut.directory.ZipRODirectory.<init>(SourceFile:54)
at brut.directory.ExtFile.getDirectory(SourceFile:51)
at brut.androlib.ApkDecoder.decodeSources(SourceFile:269)
... 2 more
Caused by: java.util.zip.ZipException: invalid CEN header (bad compression method: 27639)
at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1781)
at java.base/java.util.zip.ZipFile$Source.checkAndAddEntry(ZipFile.java:1219)
at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1720)
at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1495)
at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1458)
at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:724)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:251)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:180)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:194)
at brut.directory.ZipRODirectory.<init>(SourceFile:52)
... 4 more
Steps to Reproduce
-
java -jar apktool.jar d app.apk -o app_src -f
APK
Download - apk Password - apktool
In the past these APKs would be valid on Android, but not on PC due to the Zip spec difference. We had a custom ZipFile implementation at one point to have a less spec complaint parser, but once AOSP rejected these APKs we removed it.
I don't know if thats the case again, but my first thought.
This script (link) helped me fix this error + apktool version 2.9.0. But the AndroidManifest file looks broken.
java -jar apktool_2.9.0.jar d app.apk -o pathced_v_apk_cure
I: Using Apktool 2.9.0 on app.apk
I: Loading resource table...
S: Unknown chunk type: 6972
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/username/Library/apktool/framework/1.apk
W: Unknown chunk type at: (0x000020e0) skipping...
W: Unknown chunk type at: (0x00002148) skipping...
W: Unknown chunk type at: (0x000021c8) skipping...
W: Unknown chunk type at: (0x000021d0) skipping...
W: Unknown chunk type at: (0x000021d8) skipping...
W: Unknown chunk type at: (0x000071c0) skipping...
W: AXML hit unexpected end of file at byte: 0x71C0
I: Regular manifest package...
[Fatal Error] :2:239: Element type "manifest" must be followed by either attribute specifications, ">" or "/>".
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory
The latest version of apktool gives a different error:
java -jar apktool.jar d app.apk-o pathced_v_apk_cure
I: Using Apktool 2.12.0 on app.apk with 8 threads
I: Baksmaling classes.dex...
I: Loading resource table...
S: Unknown chunk type: 6972
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/username/Library/apktool/framework/1.apk
Exception in thread "main" brut.androlib.exceptions.RawXmlEncounteredException: Could not decode XML
at brut.androlib.res.decoder.AndroidManifestPullStreamDecoder.decode(SourceFile:53)
at brut.androlib.res.ResourcesDecoder.decodeManifest(SourceFile:202)
at brut.androlib.ApkDecoder.decodeManifest(SourceFile:242)
at brut.androlib.ApkDecoder.decode(SourceFile:85)
at brut.apktool.Main.main(SourceFile:524)
Caused by: java.io.IOException: Jumping backwards from 8416 to 8408
at brut.util.ExtDataInputStream.jumpTo(SourceFile:56)
at brut.androlib.res.decoder.AXmlResourceParser.doNext(SourceFile:780)
at brut.xmlpull.XmlPullUtils.copy(SourceFile:127)
at brut.androlib.res.decoder.AndroidManifestPullStreamDecoder.decode(SourceFile:49)
... 4 more
Yep - as I dug into this - its some bogus compression value (bad compression method: 27639) that breaks our native SDKs, which AOSP doesn't seem to care about. I don't see any method of fixing this without rolling our own Zip handler.
Thankfully in era of AI thats probably 300-400 lines of a class file, but something I have to backlog for now.
java -jar apktool_2.9.0.jar d app.apk -o pathced_v_apk_cure I: Using Apktool 2.9.0 on app.apk I: Loading resource table... S: Unknown chunk type: 6972 I: Decoding file-resources... I: Decoding values / XMLs... I: Decoding AndroidManifest.xml with resources... I: Loading resource table from file: /Users/username/Library/apktool/framework/1.apk W: Unknown chunk type at: (0x000020e0) skipping... W: Unknown chunk type at: (0x00002148) skipping... W: Unknown chunk type at: (0x000021c8) skipping... W: Unknown chunk type at: (0x000021d0) skipping... W: Unknown chunk type at: (0x000021d8) skipping... W: Unknown chunk type at: (0x000071c0) skipping... W: AXML hit unexpected end of file at byte: 0x71C0 I: Regular manifest package... [Fatal Error] :2:239: Element type "manifest" must be followed by either attribute specifications, ">" or "/>". I: Baksmaling classes.dex... I: Copying assets and libs... I: Copying unknown files... I: Copying original files... I: Copying META-INF/services directory