summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2013-11-27 16:38:17 +0100
committerYohann Roussel <yroussel@google.com>2013-12-03 13:04:48 +0000
commit4afbba6ebbd7b71774a09a9d74f2ee30352d64a1 (patch)
tree442ce7d397f15d6a73f60c463f375c244af7812c
parent6e21232cf2bca0e73bd418413564cb140ab9ccbd (diff)
downloadandroid_dalvik-4afbba6ebbd7b71774a09a9d74f2ee30352d64a1.tar.gz
android_dalvik-4afbba6ebbd7b71774a09a9d74f2ee30352d64a1.tar.bz2
android_dalvik-4afbba6ebbd7b71774a09a9d74f2ee30352d64a1.zip
Fix BufferOverflowException when merging dexes
Bug: 11519714 The bug was due to the fact that when merging 2 dexes, not enough size may be reserved for the "typeLists" section. This is because we only aligned the sum of the size of both sections. If both typeLists sections were aligned with 2 and not with 4, we are 4 bytes short when writing. Change-Id: I73b51eb25434a622143011741a69b88d42507f43 (cherry picked from commit 2241dbe132cf90b58f93c014bdd807405b7f82f5)
-rw-r--r--dx/src/com/android/dx/merge/DexMerger.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/dx/src/com/android/dx/merge/DexMerger.java b/dx/src/com/android/dx/merge/DexMerger.java
index 8080947cb..507c0766a 100644
--- a/dx/src/com/android/dx/merge/DexMerger.java
+++ b/dx/src/com/android/dx/merge/DexMerger.java
@@ -28,6 +28,7 @@ import com.android.dex.ProtoId;
import com.android.dex.SizeOf;
import com.android.dex.TableOfContents;
import com.android.dex.TypeList;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -1049,7 +1050,12 @@ public final class DexMerger {
+ contents.methodIds.size * SizeOf.MEMBER_ID_ITEM
+ contents.classDefs.size * SizeOf.CLASS_DEF_ITEM;
mapList = SizeOf.UINT + (contents.sections.length * SizeOf.MAP_ITEM);
- typeList += contents.typeLists.byteCount;
+ typeList += fourByteAlign(contents.typeLists.byteCount); // We count each dex's
+ // typelists section as realigned on 4 bytes, because each typelist of each dex's
+ // typelists section is aligned on 4 bytes. If we didn't, there is a case where each
+ // size of both dex's typelists section is a multiple of 2 but not a multiple of 4,
+ // and the sum of both sizes is a multiple of 4 but would not be sufficient to write
+ // each typelist aligned on 4 bytes.
stringData += contents.stringDatas.byteCount;
annotationsDirectory += contents.annotationsDirectories.byteCount;
annotationsSet += contents.annotationSets.byteCount;