aboutsummaryrefslogtreecommitdiff
path: root/dx
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2013-11-27 16:38:17 +0100
committerLorDClockaN <davor@losinj.com>2014-06-03 16:28:27 +0200
commite1ee903347f0456c5916b6cff50125cb77494408 (patch)
tree2a0da056c5bb20633a6f55b30a2d49e51af5634e /dx
parent439b6a953b0f14aa6c58e7b1404bc931b9320675 (diff)
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)
Diffstat (limited to 'dx')
-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;