Verify dex files in zip and from files are not CompactDex
Since there is no CompactDex verifier, dex2oat may crash for invalid
CompactDex files in the APK or directly as files. Disallow opening
these to prevent crashes.
Bug: 75967391
Bug: 63756964
Test: test-art-host-gtest
Change-Id: Ifc86f7bc2a478201473aad6481bf1e3435a910ae
diff --git a/runtime/dex/art_dex_file_loader.cc b/runtime/dex/art_dex_file_loader.cc
index c456764..9802c69 100644
--- a/runtime/dex/art_dex_file_loader.cc
+++ b/runtime/dex/art_dex_file_loader.cc
@@ -205,6 +205,12 @@
error_msg,
std::make_unique<MemMapContainer>(std::move(map)),
/*verify_result*/ nullptr);
+ // Opening CompactDex is only supported from vdex files.
+ if (dex_file != nullptr && dex_file->IsCompactDexFile()) {
+ *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files",
+ location.c_str());
+ return nullptr;
+ }
return dex_file;
}
@@ -329,6 +335,12 @@
std::make_unique<MemMapContainer>(std::move(map)),
/*verify_result*/ nullptr);
+ // Opening CompactDex is only supported from vdex files.
+ if (dex_file != nullptr && dex_file->IsCompactDexFile()) {
+ *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files",
+ location.c_str());
+ return nullptr;
+ }
return dex_file;
}
@@ -397,6 +409,11 @@
error_msg,
std::make_unique<MemMapContainer>(std::move(map)),
&verify_result);
+ if (dex_file != nullptr && dex_file->IsCompactDexFile()) {
+ *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files",
+ location.c_str());
+ return nullptr;
+ }
if (dex_file == nullptr) {
if (verify_result == VerifyResult::kVerifyNotAttempted) {
*error_code = ZipOpenErrorCode::kDexFileError;