DexFile::OpenZip should give up if correctly extracted filed fails to DexFile::OpenFile
Issue found with cts/tools/vm-tests-tf/src/dot/junit/format/f1/d/T_f1_2.dfh
Change-Id: I286141b0a4f326d52ea2bedfcd9c03e9e708f6e8
diff --git a/src/dex_file.cc b/src/dex_file.cc
index 59b92d6..b3d7144 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -221,6 +221,7 @@
std::string cache_path = StringPrintf("%s.%08x", cache_path_tmp.c_str(), zip_entry->GetCrc32());
// Example cache_path = /data/art-cache/parent@dir@foo.jar@classes.dex.1a2b3c4d
+ bool created = false;
while (true) {
if (OS::FileExists(cache_path.c_str())) {
const DexFile* cached_dex_file = DexFile::OpenFile(cache_path,
@@ -229,6 +230,11 @@
if (cached_dex_file != NULL) {
return cached_dex_file;
}
+ if (created) {
+ // We created the dex file with the correct checksum,
+ // there must be something wrong with the file itself.
+ return NULL;
+ }
}
// Try to open the temporary cache file, grabbing an exclusive
@@ -317,6 +323,8 @@
PLOG(ERROR) << "Failed to install dex cache file '" << cache_path << "'"
<< " from '" << cache_path_tmp << "'";
unlink(cache_path.c_str());
+ } else {
+ created = true;
}
}
// NOTREACHED