Incorrect parm annotation position calculation
Got the following exception when reading a DEX file.
Throwable occurred: java.lang.ArrayIndexOutOfBoundsException: 4714968
at org.ow2.asmdex.lowLevelUtils.DexFileReader.uint(DexFileReader.java:457)
at
org.ow2.asmdex.lowLevelUtils.DexFileReader.getAnnotationItemOffsetsFromAnnotationSetItem(DexFileRea
der.java:205)
at org.ow2.asmdex.ApplicationReader.readAndVisitAnnotations(ApplicationReader.java:1235)
at org.ow2.asmdex.ApplicationReader.visitMethods(ApplicationReader.java:777)
at org.ow2.asmdex.ApplicationReader.visitClass(ApplicationReader.java:614)
at org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:442)
at org.ow2.asmdex.ApplicationReader.accept(ApplicationReader.java:343)
Note that 4714968 is also the DEX file size in bytes. The DEX file is attached. I attempted to create a
simple APK to reproduce the problem but it was unsuccessful.
Using the attached DEX file I was able to track it down to the point where method
setActionBarUpIndicator(Drawable upDrawable, @StringRes int contentDescRes) of
android.support.v4.app.ActionBarDrawerToggle$Delegate is visited. Specifically,
// Visits the parameter annotations.
if (parameterAnnotationOffsetsOfClass.containsKey(methodIndex)) {
dexFile.seek(parameterAnnotationOffsetsOfClass.get(methodIndex)); //
Now pointing on anotation_set_ref_list.
int nbAnnotations = dexFile.uint(); <== RETURN 2 ANNOTATIONS
for (int annotationIndex = 0; annotationIndex < nbAnnotations;
annotationIndex++) {
int annotationSetItemOffset = dexFile.uint(); <== THE OFFSET IS
ZERO
int saveReaderPosition = dexFile.getPos();
dexFile.seek(annotationSetItemOffset);
readAndVisitAnnotations(methodVisitor, annotationIndex,
VisitorType.methodVisitor);
dexFile.seek(saveReaderPosition);
}
}
Because the annotation offset is zero causing dexFile.getAnnotationItemOffsetsFromAnnotationSetItem() to
read the entire 4714968 bytes and crash.
Dex2Jar v2 is ok but an older version (dex2jar-0.0.9.13) also encounters the same problem:
com.googlecode.dex2jar.DexException: while accept method:
[Landroid/support/v4/app/ActionBarDrawerToggle$Delegate;.setActionBarUpIndicator(Landroid/graphics/
drawable/Drawable;I)V]
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:701)
at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:448)
at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:330)
at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:84)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:239)
at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:230)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:109)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:168)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:34)
Caused by: com.googlecode.dex2jar.DexException: while accept parameter annotation in method:
[Landroid/support/v4/app/ActionBarDrawerToggle$Delegate;.setActionBarUpIndicator(Landroid/graphics/
drawable/Drawable;I)V], parameter:[0]
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:670)
... 8 more
Caused by: com.googlecode.dex2jar.DexException: Not support yet.
at com.googlecode.dex2jar.reader.Constant.ReadConstant(Constant.java:128)
at com.googlecode.dex2jar.reader.DexAnnotationReader.accept(DexAnnotationReader.java:58)
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:667)