REAndroid / APKEditor

Powerful android apk editor - aapt/aapt2 independent
Apache License 2.0
931 stars 143 forks source link

[BUG] Mismatch in zip data descriptors #124

Closed REAndroid closed 2 months ago

REAndroid commented 2 months ago
          > Caused by: com.android.apksig.zip.ZipFormatException: Data Descriptor presence mismatch between Local File Header and Central Directory for entry AndroidManifest.xml. LFH: true, CD: false

The problem is with ZIP data descriptors, it's not a problem in the signature or AndroidManifest itself, but happens for all the files that are modified during merging I think (If you remove signature and preserve AndroidManifest.xml, same Data Descriptor presence mismatch exception thrown for resources.arsc).

I thought this is a mistake in apksig, because the APK will work fine if you remove the exception, but it's not (well it might still be unnecessary validation, but as Maximoff (developer of Apktool M) noted, apksig does not throw this exception for merged APKs normally, only in ReVanced Manager/CLI, so he thinks it may be caused by something when patching).

I don't know what exactly causes it or why, but I don't think this is a problem specific to APKEditor, because APKs merged by Apktool M and AntiSplit G2 have the same problem when patching with ReVanced. In AntiSplit M I simply removed the code from REAndroid which writes data descriptor, it works fine for merging, but I don't know if it would break other functions.

Originally posted by @AbdurazaaqMohammed in https://github.com/REAndroid/APKEditor/issues/116#issuecomment-2322801093

REAndroid commented 2 months ago

@AbdurazaaqMohammed As you explained, data descriptor is placed correctly in accordance with flags. My assumption is the third party is making wrong validation, i guess the wrong validation is if entry == DEFLATED, then expect data-descriptors.

Anyways I found related issue on DataDescriptor values (crc, size, compressedSize) are always zero, it should be same as LocalFileHeader. I will try a fix on ARSCLib.

Thank you