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

java.lang.IllegalArgumentException: bad utf-8 byte dc at offset 000000eb #37

Open
iBotPeaches opened this issue Mar 2, 2024 · 6 comments

Comments

@iBotPeaches
Copy link
Contributor

I frequently am finding dex files like this and previously it was fixed in smali 2.3. Though since in this same application classes13.dex is a completely empty file - I'm partial to believing this is just a corrupted useless file.

➜  3503 java -jar ./smali/baksmali/build/libs/baksmali.jar d classes1.dex                      
Exception in thread "main" java.lang.IllegalArgumentException: bad utf-8 byte dc at offset 000000eb
	at com.android.tools.smali.util.Utf8Utils.throwBadUtf8(Utf8Utils.java:284)
	at com.android.tools.smali.util.Utf8Utils.utf8BytesWithUtf16LengthToString(Utf8Utils.java:220)
	at com.android.tools.smali.dexlib2.dexbacked.DexReader.readString(DexReader.java:610)
	at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile$5.get(DexBackedDexFile.java:326)
	at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile$5.get(DexBackedDexFile.java:319)
	at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile$6.get(DexBackedDexFile.java:362)
	at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile$6.get(DexBackedDexFile.java:357)
	at com.android.tools.smali.dexlib2.dexbacked.DexBackedClassDef.getType(DexBackedClassDef.java:107)
	at com.android.tools.smali.dexlib2.util.SyntheticAccessorResolver.<init>(SyntheticAccessorResolver.java:80)
	at com.android.tools.smali.baksmali.DisassembleCommand.getOptions(DisassembleCommand.java:287)
	at com.android.tools.smali.baksmali.DisassembleCommand.run(DisassembleCommand.java:182)
	at com.android.tools.smali.baksmali.Main.main(Main.java:101)

context: iBotPeaches/Apktool#3503
file above: classes1.zip

@sgjesse
Copy link
Collaborator

sgjesse commented Mar 11, 2024

Thank you for including the problematic dex file. It is a very small dex with only 5 strings, and looking at the encoding it is indeed an illegal encoding. Dumping the bytes of the 5 strings gives:

stringIDs.length: 5
Length of 0: 23
4c 61 6e 64 72 6f 69 64 2f 61 70 70 2f 41 63 74 69 76 69 74 79 3b 0
Length of 1: 17
4c 63 6f 6d 2f 6c 69 61 70 70 2f c 2f da dc 3b 0
Length of 2: 2
56 0
Length of 3: 3
da dc 0
Length of 4: 8
da dc 2e 6a 61 76 61 0

The two bytes 0xda and 0xdc of the last string both has the two upper bits set. If the first bytes is 0b110XXXXX then the second must be 0b10XXXXXX for a valid encoding.

I have landed https://r8-review.googlesource.com/c/r8/+/90260 to give a bit more information on the decoding issue.

chachako pushed a commit to chachako/r8 that referenced this issue Mar 11, 2024
See google/smali#37
Change-Id: Idd099efb61b3115b38598b8c5835a4e9ce0d9f52
@iBotPeaches
Copy link
Contributor Author

thanks! I'll close this out when I see it land in GitHub

@sgjesse
Copy link
Collaborator

sgjesse commented Mar 12, 2024

The R8 source is not in GitHub, but on googlesource.com. Change with better error reporting is in 8.4.21-dev.

@iBotPeaches
Copy link
Contributor Author

Thanks apologies - I was so used to just watching smali in GitHub and was unaware of parent dependencies and how they played out in Google ecosystem.

@sgjesse
Copy link
Collaborator

sgjesse commented Mar 12, 2024

That said, let's keep this open, and I will extend the error messages in dexlib2/src/main/java/com/android/tools/smali/util/Utf8Utils.java to what I added to R8.

@iBotPeaches
Copy link
Contributor Author

Thanks for the reference/link to R8 @sgjesse - I had no idea it worked for regular Java projects. I moved Apktool over and it seems to have solved my last remaining issues on the way to making reproducible builds - iBotPeaches/Apktool#3559

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

No branches or pull requests

2 participants