Bug fix for segfault on reading bytecode with dexdump.
Rationale:
An incorrect type (signed vs. unsigned) compare did not guard
subsequent access of memory correctly.
BUG=28038148
Change-Id: I7aa97ad252614e3d045297cce314b5a4b96a60b2
diff --git a/libdex/DexFile.h b/libdex/DexFile.h
index 593d414..6c4d0d8 100644
--- a/libdex/DexFile.h
+++ b/libdex/DexFile.h
@@ -606,7 +606,7 @@
*
* Return 0 on success.
*/
-int dexSwapAndVerifyIfNecessary(u1* addr, int len);
+int dexSwapAndVerifyIfNecessary(u1* addr, size_t len);
/*
* Check to see if the file magic and format version in the given
diff --git a/libdex/DexSwapVerify.cpp b/libdex/DexSwapVerify.cpp
index 2b653b8..eafc1a7 100644
--- a/libdex/DexSwapVerify.cpp
+++ b/libdex/DexSwapVerify.cpp
@@ -2813,7 +2813,7 @@
*
* Returns 0 on success, nonzero on failure.
*/
-int dexSwapAndVerify(u1* addr, int len)
+int dexSwapAndVerify(u1* addr, size_t len)
{
DexHeader* pHeader;
CheckState state;
@@ -2833,13 +2833,13 @@
}
if (okay) {
- int expectedLen = (int) SWAP4(pHeader->fileSize);
+ u4 expectedLen = SWAP4(pHeader->fileSize);
if (len < expectedLen) {
- ALOGE("ERROR: Bad length: expected %d, got %d", expectedLen, len);
+ ALOGE("ERROR: Bad length: expected %u, got %zu", expectedLen, len);
okay = false;
} else if (len != expectedLen) {
- ALOGW("WARNING: Odd length: expected %d, got %d", expectedLen,
- len);
+ ALOGW("WARNING: Odd length: expected %u, got %zu", expectedLen,
+ len);
// keep going
}
}
@@ -2939,7 +2939,7 @@
*
* Returns 0 on success, nonzero on failure.
*/
-int dexSwapAndVerifyIfNecessary(u1* addr, int len)
+int dexSwapAndVerifyIfNecessary(u1* addr, size_t len)
{
if (memcmp(addr, DEX_OPT_MAGIC, 4) == 0) {
// It is an optimized dex file.