internal dex lib: const-string not widened to /jumbo when dex has >65535 strings (Short value out of range; jf handles it)

Aperta
#245 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, java
Ambito
build-system

Direzione di ricerca

The exception is raised from SizeXIns.setShort at SizeXIns.java:99 in the com.reandroid.dex.ins package, reached while building a const-string (21c) whose string index exceeds 0xffff. Start there, then look at where const-string instructions are chosen or encoded and at how the existing const-string/jumbo (31c) path is written. Reproduce with a dex holding more than 65535 strings and one added const-string. Done means such an instruction is widened to const-string/jumbo, branch offsets are relaid out, and the rebuilt dex reads cleanly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

Regression from V1.4.1 to V1.4.9: when a dex already has more than 65535 strings, adding a class or a string to it makes b fail on a plain const-string. V1.4.1 builds the same input fine: it widened the affected const-string to const-string/jumbo automatically. V1.4.9 throws instead:

com.reandroid.dex.ins.InstructionException: Short value out of range 0x1253f > 0xffff, dex = classes3.dex, class = Lcom/android/systemui/kashi/NotificationRedClockHelper$3;, method = ... { ... const-string ... }
	at com.reandroid.dex.ins.SizeXIns.setShort(SizeXIns.java:99)

This is not about the dex being out of space. A dex can hold far more than 65535 strings (the one below ends up with 75477), and const-string/jumbo exists for exactly this case. Strings are sorted, so adding new ones shifts the index of existing ones. A const-string that fit at decompile time can end up past 0xffff, and the smali author has no way to know that ahead of time.

Same root cause as #236 (closed without a fix) and probably #231.

To Reproduce

  1. Used version: V1.4.9 (official release jar). Works with V1.4.1.
  2. Operating system: Linux (also seen on GitHub Actions ubuntu runners)
  3. Commands:
# any apk with a dex past 65535 strings (here MIUI SystemUI, classes3.dex = ~75K strings;
# its smali already contains ~3900 const-string/jumbo)
java -jar APKEditor.jar d -t raw -i SystemUI.apk -o out -f
# add any new class with a few new strings to that dex
cp NewHelper.smali out/smali/classes3/com/example/
java -jar APKEditor.jar b -t raw -i out -o rebuilt.apk -f

Rebuilding without changes works with both versions, because the dex is cached. With the added class:

version result
V1.4.1 builds. Output classes3.dex has 3950 const-string/jumbo (source smali: 3906), and dexdump reads it cleanly
V1.4.9 InstructionException: Short value out of range ... const-string

Expected

As in V1.4.1 (and like d8 does): when a const-string (21c) has a string index above 0xffff, encode it as const-string/jumbo (31c) instead of throwing, then re-layout branch offsets as for any instruction size change.

Workaround

Rewrite every const-string in the affected dex's smali as const-string/jumbo before building. This builds fine with V1.4.9, which shows the writer itself handles jumbo correctly. Only the automatic widening is missing.

Lingua principale
Java
Stelle
2.3k
Fork
417
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di REAndroid/APKEditor

Tutte le issue di REAndroid/APKEditor

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.