Make DexFile content read only before running DexFileVerifier
(cherry picked from commit 98725444129efe2b1b51c87740860caadaef2bf7)
Change-Id: I18a932b2f19d44b820232f4d4e9c358df20ab364
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 9cb2f1b..3ff55ab 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -258,15 +258,15 @@
error_msg->c_str());
return nullptr;
}
- if (!DexFileVerifier::Verify(dex_file.get(), dex_file->Begin(), dex_file->Size(),
- location.c_str(), error_msg)) {
- return nullptr;
- }
if (!dex_file->DisableWrite()) {
*error_msg = StringPrintf("Failed to make dex file '%s' read only", location.c_str());
return nullptr;
}
CHECK(dex_file->IsReadOnly()) << location;
+ if (!DexFileVerifier::Verify(dex_file.get(), dex_file->Begin(), dex_file->Size(),
+ location.c_str(), error_msg)) {
+ return nullptr;
+ }
return dex_file.release();
}