Fix for data type mismatch which confuses safemul.
The 64-bit version of dexdump failed with a
"Byte swap + verify failed" error, caused by
the use of data types u4 vs. size_t in a safemul.
On 32-bit this works, but the larger size of size_t
on 64-bit causes a mismatch error.
Bug has now been fixed. Both 32-bit and 64-bit binary
generate the same dexdump output.
This CL also reverses the workaround for the bug
(SHA dc43b33cb50252bde27c11e54f8f977d32660028)
that simply restricted the build to 32-bit only.
Bug: 17442393
Change-Id: Ib51b5d1ecba173f2c2fa2cf884bffa893ce60a53
diff --git a/dexdump/Android.mk b/dexdump/Android.mk
index 72dd7e6..9e7e92a 100644
--- a/dexdump/Android.mk
+++ b/dexdump/Android.mk
@@ -46,7 +46,6 @@
LOCAL_MODULE_TAGS := optional
LOCAL_LDLIBS +=
LOCAL_32_BIT_ONLY := true
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
@@ -57,7 +56,6 @@
LOCAL_SHARED_LIBRARIES := libutils
LOCAL_MODULE_TAGS := optional
LOCAL_32_BIT_ONLY := true
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_STATIC_LIBRARY)
endif # !SDK_ONLY
@@ -79,7 +77,4 @@
else
LOCAL_LDLIBS += -lpthread -lz
endif
-# TODO: Move dexdump from libdex to libart and lose the 32-bit limitation.
-LOCAL_32_BIT_ONLY := true
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_HOST_EXECUTABLE)
diff --git a/libdex/Android.mk b/libdex/Android.mk
index 15e7ba7..cabc8dc 100644
--- a/libdex/Android.mk
+++ b/libdex/Android.mk
@@ -56,7 +56,6 @@
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libdex
LOCAL_32_BIT_ONLY := true
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_STATIC_LIBRARY)
endif # !SDK_ONLY
@@ -75,6 +74,4 @@
LOCAL_WHOLE_STATIC_LIBRARIES := libziparchive-host
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libdex
-LOCAL_32_BIT_ONLY := true
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/libdex/DexDataMap.cpp b/libdex/DexDataMap.cpp
index 8405e8c..65da14c 100644
--- a/libdex/DexDataMap.cpp
+++ b/libdex/DexDataMap.cpp
@@ -36,7 +36,8 @@
/*
* Avoiding pulling in safe_iop for safe_iopf.
*/
- if (!safe_mul(&size, maxCount, sizeof(u4) + sizeof(u2)) ||
+ const u4 sizeOfItems = (u4) (sizeof(u4) + sizeof(u2));
+ if (!safe_mul(&size, maxCount, sizeOfItems) ||
!safe_add(&size, size, sizeof(DexDataMap))) {
return NULL;
}
diff --git a/libdex/DexSwapVerify.cpp b/libdex/DexSwapVerify.cpp
index 7f18831..46ce141 100644
--- a/libdex/DexSwapVerify.cpp
+++ b/libdex/DexSwapVerify.cpp
@@ -378,8 +378,8 @@
SWAP_FIELD4(pMap->size);
count = pMap->size;
-
- CHECK_LIST_SIZE(item, count, sizeof(DexMapItem));
+ const u4 sizeOfItem = (u4) sizeof(DexMapItem);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_FIELD2(item->type);
@@ -1044,7 +1044,8 @@
bool first = true;
u4 lastIdx = 0;
- CHECK_LIST_SIZE(item, count, sizeof(DexFieldAnnotationsItem));
+ const u4 sizeOfItem = (u4) sizeof(DexFieldAnnotationsItem);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_INDEX4(item->fieldIdx, state->pHeader->fieldIdsSize);
@@ -1073,7 +1074,8 @@
bool first = true;
u4 lastIdx = 0;
- CHECK_LIST_SIZE(item, count, sizeof(DexMethodAnnotationsItem));
+ const u4 sizeOfItem = (u4) sizeof(DexMethodAnnotationsItem);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_INDEX4(item->methodIdx, state->pHeader->methodIdsSize);
@@ -1103,7 +1105,8 @@
bool first = true;
u4 lastIdx = 0;
- CHECK_LIST_SIZE(item, count, sizeof(DexParameterAnnotationsItem));
+ const u4 sizeOfItem = (u4) sizeof(DexParameterAnnotationsItem);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_INDEX4(item->methodIdx, state->pHeader->methodIdsSize);
@@ -1305,7 +1308,9 @@
SWAP_FIELD4(pTypeList->size);
count = pTypeList->size;
pType = pTypeList->list;
- CHECK_LIST_SIZE(pType, count, sizeof(DexTypeItem));
+
+ const u4 sizeOfItem = (u4) sizeof(DexTypeItem);
+ CHECK_LIST_SIZE(pType, count, sizeOfItem);
while (count--) {
SWAP_INDEX2(pType->typeIdx, state->pHeader->typeIdsSize);
@@ -1326,7 +1331,9 @@
SWAP_FIELD4(list->size);
count = list->size;
item = list->list;
- CHECK_LIST_SIZE(item, count, sizeof(DexAnnotationSetRefItem));
+
+ const u4 sizeOfItem = (u4) sizeof(DexAnnotationSetRefItem);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_OFFSET4(item->annotationsOff);
@@ -1365,7 +1372,9 @@
SWAP_FIELD4(set->size);
count = set->size;
item = set->entries;
- CHECK_LIST_SIZE(item, count, sizeof(u4));
+
+ const u4 sizeOfItem = (u4) sizeof(u4);
+ CHECK_LIST_SIZE(item, count, sizeOfItem);
while (count--) {
SWAP_OFFSET4(*item);
@@ -1739,7 +1748,8 @@
u4 count = code->triesSize;
u4 lastEnd = 0;
- CHECK_LIST_SIZE(tries, count, sizeof(DexTry));
+ const u4 sizeOfItem = (u4) sizeof(DexTry);
+ CHECK_LIST_SIZE(tries, count, sizeOfItem);
while (count--) {
u4 i;
@@ -1818,7 +1828,9 @@
count = item->insnsSize;
insns = item->insns;
- CHECK_LIST_SIZE(insns, count, sizeof(u2));
+
+ const u4 sizeOfItem = (u4) sizeof(u2);
+ CHECK_LIST_SIZE(insns, count, sizeOfItem);
while (count--) {
*insns = SWAP2(*insns);