Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: Commit

dalvik


Commit MetaInfo

Revision4afbba6ebbd7b71774a09a9d74f2ee30352d64a1 (tree)
Time2013-12-03 22:04:48
AuthorBenoit Lamarche <benoitlamarche@goog...>
CommiterYohann Roussel

Log Message

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)

Change Summary

Incremental Difference

--- 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;
2828 import com.android.dex.SizeOf;
2929 import com.android.dex.TableOfContents;
3030 import com.android.dex.TypeList;
31+
3132 import java.io.File;
3233 import java.io.IOException;
3334 import java.util.ArrayList;
@@ -1049,7 +1050,12 @@ public final class DexMerger {
10491050 + contents.methodIds.size * SizeOf.MEMBER_ID_ITEM
10501051 + contents.classDefs.size * SizeOf.CLASS_DEF_ITEM;
10511052 mapList = SizeOf.UINT + (contents.sections.length * SizeOf.MAP_ITEM);
1052- typeList += contents.typeLists.byteCount;
1053+ typeList += fourByteAlign(contents.typeLists.byteCount); // We count each dex's
1054+ // typelists section as realigned on 4 bytes, because each typelist of each dex's
1055+ // typelists section is aligned on 4 bytes. If we didn't, there is a case where each
1056+ // size of both dex's typelists section is a multiple of 2 but not a multiple of 4,
1057+ // and the sum of both sizes is a multiple of 4 but would not be sufficient to write
1058+ // each typelist aligned on 4 bytes.
10531059 stringData += contents.stringDatas.byteCount;
10541060 annotationsDirectory += contents.annotationsDirectories.byteCount;
10551061 annotationsSet += contents.annotationSets.byteCount;
Show on old repository browser