Return error directly when uncompressed length is 0
If uncompressed length is 0, in function MemMap::MapAnonymous, it will generate a MemMap instance whose base_begin is nullptr.
Then, when OpenMemory, it will create a DexFile instance.
At DexFile::DexFile constructor, header_ is asigned to 0, then header_->string_ids_off_ will cause crash.
Bug: b/28856653
Test: test-art-host-gtest-dex_file_test
Signed-off-by: ganxiaolin <ganxiaolin@xiaomi.com>
Change-Id: Id37f7629f4646cbc385ef054cb83b15be4c59b00
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 061babd..dff2802 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -338,6 +338,11 @@
*error_code = ZipOpenErrorCode::kEntryNotFound;
return nullptr;
}
+ if (zip_entry->GetUncompressedLength() == 0) {
+ *error_msg = StringPrintf("Dex file '%s' has zero length", location.c_str());
+ *error_code = ZipOpenErrorCode::kDexFileError;
+ return nullptr;
+ }
std::unique_ptr<MemMap> map(zip_entry->ExtractToMemMap(location.c_str(), entry_name, error_msg));
if (map.get() == nullptr) {
*error_msg = StringPrintf("Failed to extract '%s' from '%s': %s", entry_name, location.c_str(),
@@ -435,6 +440,8 @@
MemMap* mem_map,
const OatDexFile* oat_dex_file,
std::string* error_msg) {
+ DCHECK(base != nullptr);
+ DCHECK_NE(size, 0UL);
CHECK_ALIGNED(base, 4); // various dex file structures must be word aligned
std::unique_ptr<DexFile> dex_file(
new DexFile(base, size, location, location_checksum, mem_map, oat_dex_file));