Pass the verify flag to DexFileLoader utilities.
Refactoring-only change.
Also remove unused DexFilerLoader::OpenMemory.
bug: 30972906
bug: 63920015
Test: build.
Change-Id: I7cd4b5787565ab1a3457ce2be6bb14657229c550
diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc
index ae7ebe2..0a50681 100644
--- a/dex2oat/dex2oat_image_test.cc
+++ b/dex2oat/dex2oat_image_test.cc
@@ -65,6 +65,7 @@
std::string error_msg;
CHECK(DexFileLoader::Open(dex.c_str(),
dex,
+ /*verify*/ true,
/*verify_checksum*/ false,
&error_msg,
&dex_files))
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 1b731fc..dc1d54f 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -678,7 +678,8 @@
const char* location = dex_location.c_str();
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- ASSERT_TRUE(DexFileLoader::Open(location, location, true, &error_msg, &dex_files));
+ ASSERT_TRUE(DexFileLoader::Open(
+ location, location, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files));
EXPECT_EQ(dex_files.size(), 1U);
std::unique_ptr<const DexFile>& dex_file = dex_files[0];
GenerateProfile(profile_location,
@@ -812,7 +813,8 @@
const char* location = dex_location.c_str();
std::vector<std::unique_ptr<const DexFile>> dex_files;
- ASSERT_TRUE(DexFileLoader::Open(location, location, true, &error_msg, &dex_files));
+ ASSERT_TRUE(DexFileLoader::Open(
+ location, location, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files));
EXPECT_EQ(dex_files.size(), 1U);
std::unique_ptr<const DexFile>& old_dex_file = dex_files[0];
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 17ceca3..702358e 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -3259,7 +3259,8 @@
PLOG(ERROR) << "Failed to dup dex file descriptor (" << raw_file->Fd() << ") at " << location;
return false;
}
- dex_file = DexFileLoader::OpenDex(dup_fd, location, /* verify_checksum */ true, &error_msg);
+ dex_file = DexFileLoader::OpenDex(
+ dup_fd, location, /* verify */ true, /* verify_checksum */ true, &error_msg);
} else {
// The source data is a vdex file.
CHECK(oat_dex_file->source_.IsRawData())
diff --git a/dexdump/dexdump.cc b/dexdump/dexdump.cc
index 3648a3e..4bfd91f 100644
--- a/dexdump/dexdump.cc
+++ b/dexdump/dexdump.cc
@@ -1883,7 +1883,8 @@
const bool kVerifyChecksum = !gOptions.ignoreBadChecksum;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- if (!DexFileLoader::Open(fileName, fileName, kVerifyChecksum, &error_msg, &dex_files)) {
+ if (!DexFileLoader::Open(
+ fileName, fileName, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) {
// Display returned error message to user. Note that this error behavior
// differs from the error messages shown by the original Dalvik dexdump.
fputs(error_msg.c_str(), stderr);
diff --git a/dexlayout/dexlayout.cc b/dexlayout/dexlayout.cc
index 40449ae..7dfe629 100644
--- a/dexlayout/dexlayout.cc
+++ b/dexlayout/dexlayout.cc
@@ -2062,7 +2062,8 @@
const bool verify_checksum = !options_.ignore_bad_checksum_;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- if (!DexFileLoader::Open(file_name, file_name, verify_checksum, &error_msg, &dex_files)) {
+ if (!DexFileLoader::Open(
+ file_name, file_name, /* verify */ true, verify_checksum, &error_msg, &dex_files)) {
// Display returned error message to user. Note that this error behavior
// differs from the error messages shown by the original Dalvik dexdump.
fputs(error_msg.c_str(), stderr);
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc
index f8fa893..f34e7ec 100644
--- a/dexlayout/dexlayout_test.cc
+++ b/dexlayout/dexlayout_test.cc
@@ -325,7 +325,8 @@
std::string error_msg;
bool result = DexFileLoader::Open(input_dex.c_str(),
input_dex,
- false,
+ /*verify*/ true,
+ /*verify_checksum*/ false,
&error_msg,
&dex_files);
diff --git a/dexlist/dexlist.cc b/dexlist/dexlist.cc
index e587052..c8bc132 100644
--- a/dexlist/dexlist.cc
+++ b/dexlist/dexlist.cc
@@ -179,7 +179,8 @@
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- if (!DexFileLoader::Open(fileName, fileName, kVerifyChecksum, &error_msg, &dex_files)) {
+ if (!DexFileLoader::Open(
+ fileName, fileName, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) {
fputs(error_msg.c_str(), stderr);
fputc('\n', stderr);
return -1;
diff --git a/openjdkjvmti/ti_search.cc b/openjdkjvmti/ti_search.cc
index bafc855..5c67b89 100644
--- a/openjdkjvmti/ti_search.cc
+++ b/openjdkjvmti/ti_search.cc
@@ -227,7 +227,8 @@
std::string error_msg;
std::vector<std::unique_ptr<const art::DexFile>> dex_files;
- if (!art::DexFileLoader::Open(segment, segment, true, &error_msg, &dex_files)) {
+ if (!art::DexFileLoader::Open(
+ segment, segment, /* verify */ true, /* verify_checksum */ true, &error_msg, &dex_files)) {
LOG(WARNING) << "Could not open " << segment << " for boot classpath extension: " << error_msg;
return ERR(ILLEGAL_ARGUMENT);
}
diff --git a/profman/profman.cc b/profman/profman.cc
index 8ccf7b4..4c4bb87 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -331,6 +331,7 @@
if (use_apk_fd_list) {
if (DexFileLoader::OpenZip(apks_fd_[i],
dex_locations_[i],
+ /* verify */ true,
kVerifyChecksum,
&error_msg,
&dex_files_for_location)) {
@@ -341,6 +342,7 @@
} else {
if (DexFileLoader::Open(apk_files_[i].c_str(),
dex_locations_[i],
+ /* verify */ true,
kVerifyChecksum,
&error_msg,
&dex_files_for_location)) {
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 167533d..5510743 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -230,6 +230,7 @@
// contents. So pass true to verify_checksum.
if (!DexFileLoader::Open(location.c_str(),
location.c_str(),
+ /*verify*/ true,
/*verify_checksum*/ true,
&error_msg,
&info.opened_dex_files)) {
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 0c2e490..d35402f 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -373,7 +373,8 @@
std::string error_msg;
MemMap::Init();
static constexpr bool kVerifyChecksum = true;
- if (!DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files)) {
+ if (!DexFileLoader::Open(
+ location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) {
LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n";
UNREACHABLE();
} else {
@@ -572,8 +573,11 @@
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- bool success = DexFileLoader::Open(
- filename.c_str(), filename.c_str(), kVerifyChecksum, &error_msg, &dex_files);
+ bool success = DexFileLoader::Open(filename.c_str(),
+ filename.c_str(),
+ /* verify */ true,
+ kVerifyChecksum,
+ &error_msg, &dex_files);
CHECK(success) << "Failed to open '" << filename << "': " << error_msg;
for (auto& dex_file : dex_files) {
CHECK_EQ(PROT_READ, dex_file->GetPermissions());
diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h
index a9bb954..57cef3d 100644
--- a/runtime/dex2oat_environment_test.h
+++ b/runtime/dex2oat_environment_test.h
@@ -84,6 +84,7 @@
std::vector<std::unique_ptr<const DexFile>> multi1;
ASSERT_TRUE(DexFileLoader::Open(GetMultiDexSrc1().c_str(),
GetMultiDexSrc1().c_str(),
+ /* verify */ true,
kVerifyChecksum,
&error_msg,
&multi1)) << error_msg;
@@ -92,6 +93,7 @@
std::vector<std::unique_ptr<const DexFile>> multi2;
ASSERT_TRUE(DexFileLoader::Open(GetMultiDexSrc2().c_str(),
GetMultiDexSrc2().c_str(),
+ /* verify */ true,
kVerifyChecksum,
&error_msg,
&multi2)) << error_msg;
diff --git a/runtime/dex_file_loader.cc b/runtime/dex_file_loader.cc
index e300e0e..d581eb7 100644
--- a/runtime/dex_file_loader.cc
+++ b/runtime/dex_file_loader.cc
@@ -186,6 +186,7 @@
bool DexFileLoader::Open(const char* filename,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files) {
@@ -198,12 +199,12 @@
return false;
}
if (IsZipMagic(magic)) {
- return OpenZip(fd.Release(), location, verify_checksum, error_msg, dex_files);
+ return OpenZip(fd.Release(), location, verify, verify_checksum, error_msg, dex_files);
}
if (IsMagicValid(magic)) {
std::unique_ptr<const DexFile> dex_file(OpenFile(fd.Release(),
location,
- /* verify */ true,
+ verify,
verify_checksum,
error_msg));
if (dex_file.get() != nullptr) {
@@ -219,14 +220,16 @@
std::unique_ptr<const DexFile> DexFileLoader::OpenDex(int fd,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg) {
ScopedTrace trace("Open dex file " + std::string(location));
- return OpenFile(fd, location, true /* verify */, verify_checksum, error_msg);
+ return OpenFile(fd, location, verify, verify_checksum, error_msg);
}
bool DexFileLoader::OpenZip(int fd,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files) {
@@ -237,7 +240,8 @@
DCHECK(!error_msg->empty());
return false;
}
- return OpenAllDexFilesFromZip(*zip_archive, location, verify_checksum, error_msg, dex_files);
+ return OpenAllDexFilesFromZip(
+ *zip_archive, location, verify, verify_checksum, error_msg, dex_files);
}
std::unique_ptr<const DexFile> DexFileLoader::OpenFile(int fd,
@@ -304,6 +308,7 @@
const ZipArchive& zip_archive,
const char* entry_name,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
ZipOpenErrorCode* error_code) {
@@ -357,7 +362,7 @@
location,
zip_entry->GetCrc32(),
kNoOatDexFile,
- /* verify */ true,
+ verify,
verify_checksum,
error_msg,
&verify_result);
@@ -391,16 +396,18 @@
static constexpr size_t kWarnOnManyDexFilesThreshold = 100;
bool DexFileLoader::OpenAllDexFilesFromZip(const ZipArchive& zip_archive,
- const std::string& location,
- bool verify_checksum,
- std::string* error_msg,
- std::vector<std::unique_ptr<const DexFile>>* dex_files) {
+ const std::string& location,
+ bool verify,
+ bool verify_checksum,
+ std::string* error_msg,
+ std::vector<std::unique_ptr<const DexFile>>* dex_files) {
ScopedTrace trace("Dex file open from Zip " + std::string(location));
DCHECK(dex_files != nullptr) << "DexFile::OpenFromZip: out-param is nullptr";
ZipOpenErrorCode error_code;
std::unique_ptr<const DexFile> dex_file(OpenOneDexFileFromZip(zip_archive,
kClassesDex,
location,
+ verify,
verify_checksum,
error_msg,
&error_code));
@@ -421,6 +428,7 @@
std::unique_ptr<const DexFile> next_dex_file(OpenOneDexFileFromZip(zip_archive,
name.c_str(),
fake_location,
+ verify,
verify_checksum,
error_msg,
&error_code));
diff --git a/runtime/dex_file_loader.h b/runtime/dex_file_loader.h
index cb17ecc..a1167dc 100644
--- a/runtime/dex_file_loader.h
+++ b/runtime/dex_file_loader.h
@@ -79,6 +79,7 @@
// Opens all .dex files found in the file, guessing the container format based on file extension.
static bool Open(const char* filename,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files);
@@ -86,12 +87,14 @@
// Open a single dex file from an fd. This function closes the fd.
static std::unique_ptr<const DexFile> OpenDex(int fd,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg);
// Opens dex files from within a .jar, .zip, or .apk file
static bool OpenZip(int fd,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files);
@@ -158,6 +161,7 @@
// Open all classesXXX.dex files from a zip archive.
static bool OpenAllDexFilesFromZip(const ZipArchive& zip_archive,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files);
@@ -167,6 +171,7 @@
static std::unique_ptr<const DexFile> OpenOneDexFileFromZip(const ZipArchive& zip_archive,
const char* entry_name,
const std::string& location,
+ bool verify,
bool verify_checksum,
std::string* error_msg,
ZipOpenErrorCode* error_code);
@@ -186,16 +191,6 @@
bool verify_checksum,
std::string* error_msg,
VerifyResult* verify_result = nullptr);
-
-
- // Opens a .dex file at the given address, optionally backed by a MemMap
- static std::unique_ptr<const DexFile> OpenMemory(const uint8_t* dex_file,
- size_t size,
- const std::string& location,
- uint32_t location_checksum,
- std::unique_ptr<MemMap> mem_map,
- const OatDexFile* oat_dex_file,
- std::string* error_msg);
};
} // namespace art
diff --git a/runtime/dex_file_test.cc b/runtime/dex_file_test.cc
index b301137..90bc4b8 100644
--- a/runtime/dex_file_test.cc
+++ b/runtime/dex_file_test.cc
@@ -236,7 +236,8 @@
ScopedObjectAccess soa(Thread::Current());
static constexpr bool kVerifyChecksum = true;
std::vector<std::unique_ptr<const DexFile>> tmp;
- bool success = DexFileLoader::Open(location, location, kVerifyChecksum, error_msg, &tmp);
+ bool success = DexFileLoader::Open(
+ location, location, /* verify */ true, kVerifyChecksum, error_msg, &tmp);
if (success) {
for (std::unique_ptr<const DexFile>& dex_file : tmp) {
EXPECT_EQ(PROT_READ, dex_file->GetPermissions());
@@ -366,7 +367,8 @@
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files));
+ ASSERT_FALSE(DexFileLoader::Open(
+ location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files));
}
TEST_F(DexFileTest, Version41Rejected) {
@@ -378,7 +380,8 @@
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files));
+ ASSERT_FALSE(DexFileLoader::Open(
+ location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files));
}
TEST_F(DexFileTest, ZeroLengthDexRejected) {
@@ -390,7 +393,8 @@
static constexpr bool kVerifyChecksum = true;
std::string error_msg;
std::vector<std::unique_ptr<const DexFile>> dex_files;
- ASSERT_FALSE(DexFileLoader::Open(location, location, kVerifyChecksum, &error_msg, &dex_files));
+ ASSERT_FALSE(DexFileLoader::Open(
+ location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files));
}
TEST_F(DexFileTest, GetLocationChecksum) {
diff --git a/runtime/dex_file_verifier_test.cc b/runtime/dex_file_verifier_test.cc
index 9f3505d..7bda89d 100644
--- a/runtime/dex_file_verifier_test.cc
+++ b/runtime/dex_file_verifier_test.cc
@@ -114,7 +114,8 @@
// read dex file
ScopedObjectAccess soa(Thread::Current());
std::vector<std::unique_ptr<const DexFile>> tmp;
- bool success = DexFileLoader::Open(location, location, true, error_msg, &tmp);
+ bool success = DexFileLoader::Open(
+ location, location, /* verify */ true, /* verify_checksum */ true, error_msg, &tmp);
CHECK(success) << *error_msg;
EXPECT_EQ(1U, tmp.size());
std::unique_ptr<const DexFile> dex_file = std::move(tmp[0]);
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 1e7cf72..a3cbe95 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -597,8 +597,12 @@
if (oat_file_assistant.HasOriginalDexFiles()) {
if (Runtime::Current()->IsDexFileFallbackEnabled()) {
static constexpr bool kVerifyChecksum = true;
- if (!DexFileLoader::Open(
- dex_location, dex_location, kVerifyChecksum, /*out*/ &error_msg, &dex_files)) {
+ if (!DexFileLoader::Open(dex_location,
+ dex_location,
+ /*verify*/ true,
+ kVerifyChecksum,
+ /*out*/ &error_msg,
+ &dex_files)) {
LOG(WARNING) << error_msg;
error_msgs->push_back("Failed to open dex files from " + std::string(dex_location)
+ " because: " + error_msg);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 7f2f789..a9db487 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1026,7 +1026,8 @@
LOG(WARNING) << "Skipping non-existent dex file '" << dex_filename << "'";
continue;
}
- if (!DexFileLoader::Open(dex_filename, dex_location, kVerifyChecksum, &error_msg, dex_files)) {
+ if (!DexFileLoader::Open(
+ dex_filename, dex_location, /* verify */ true, kVerifyChecksum, &error_msg, dex_files)) {
LOG(WARNING) << "Failed to open .dex from file '" << dex_filename << "': " << error_msg;
++failure_count;
}