Reject a vdex file if its dex contents are out of date.
This will make sure the runtime doesn't think the APK optimization state
is "verify", when at runtime we'll actually run from the APK
Test: m
Bug: 191245631
Change-Id: I46e056e52d1f7ff4a4ec8d952f325c54d9efad8f
Merged-In: I46e056e52d1f7ff4a4ec8d952f325c54d9efad8f
(cherry picked from commit f5690ca22446968e6c28ebb06b1d7451e02e203d)
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 8a5ad63..49d5e61 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -803,20 +803,18 @@
const bool valid_magic = DexFileLoader::IsMagicValid(dex_file_pointer);
if (UNLIKELY(!valid_magic)) {
*error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with invalid "
- "dex file magic '%s'",
+ "dex file magic",
GetLocation().c_str(),
i,
- dex_file_location.c_str(),
- dex_file_pointer);
+ dex_file_location.c_str());
return false;
}
if (UNLIKELY(!DexFileLoader::IsVersionAndMagicValid(dex_file_pointer))) {
*error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with invalid "
- "dex file version '%s'",
+ "dex file version",
GetLocation().c_str(),
i,
- dex_file_location.c_str(),
- dex_file_pointer);
+ dex_file_location.c_str());
return false;
}
const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer);
@@ -1603,6 +1601,12 @@
for (const uint8_t* dex_file_start = vdex_file->GetNextDexFileData(nullptr, i);
dex_file_start != nullptr;
dex_file_start = vdex_file->GetNextDexFileData(dex_file_start, ++i)) {
+ if (UNLIKELY(!DexFileLoader::IsVersionAndMagicValid(dex_file_start))) {
+ *error_msg =
+ StringPrintf("In vdex file '%s' found dex file with invalid dex file version",
+ dex_location.c_str());
+ return nullptr;
+ }
// Create the OatDexFile and add it to the owning container.
std::string location = DexFileLoader::GetMultiDexLocation(i, dex_location.c_str());
std::string canonical_location = DexFileLoader::GetDexCanonicalLocation(location.c_str());