summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2018-03-22 16:46:45 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2018-03-22 16:46:45 +0000
commitf0edca6df56a60e6129a93b3ab6db13cabeb7c5e (patch)
tree0f1913f3c63c6f300dc4029f41bb817ab312bc0b
parentf82ddf2475719c76505f4830d82020fe1f12182b (diff)
parentd45863a976c2fd10cf179d8ff42926a7a37c70f0 (diff)
Merge "Run dex verifier for OOB + compact-dex-level combination"
-rw-r--r--dex2oat/dex2oat.cc8
-rw-r--r--dex2oat/dex2oat_test.cc33
-rw-r--r--libdexfile/dex/dex_file_loader.cc2
3 files changed, 38 insertions, 5 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 9b370178f7..6950b93e51 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1609,11 +1609,9 @@ class Dex2Oat FINAL {
// Unzip or copy dex files straight to the oat file.
std::vector<std::unique_ptr<MemMap>> opened_dex_files_map;
std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
- // No need to verify the dex file for:
- // 1) Dexlayout since it does the verification. It also may not pass the verification since
- // we don't update the dex checksum.
- // 2) when we have a vdex file, which means it was already verified.
- const bool verify = !DoDexLayoutOptimizations() && (input_vdex_file_ == nullptr);
+ // No need to verify the dex file when we have a vdex file, which means it was already
+ // verified.
+ const bool verify = (input_vdex_file_ == nullptr);
if (!oat_writers_[i]->WriteAndOpenDexFiles(
vdex_files_[i].get(),
rodata_.back(),
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 5590c8b3ab..5e9782aadf 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -2013,4 +2013,37 @@ TEST_F(Dex2oatTest, QuickenedInput) {
ASSERT_EQ(vdex_unquickened->FlushCloseOrErase(), 0) << "Could not flush and close";
}
+// Test that compact dex generation with invalid dex files doesn't crash dex2oat. b/75970654
+TEST_F(Dex2oatTest, CompactDexInvalidSource) {
+ ScratchFile invalid_dex;
+ {
+ FILE* file = fdopen(invalid_dex.GetFd(), "w+b");
+ ZipWriter writer(file);
+ writer.StartEntry("classes.dex", ZipWriter::kAlign32);
+ DexFile::Header header = {};
+ StandardDexFile::WriteMagic(header.magic_);
+ StandardDexFile::WriteCurrentVersion(header.magic_);
+ header.file_size_ = 4 * KB;
+ header.data_size_ = 4 * KB;
+ header.data_off_ = 10 * MB;
+ header.map_off_ = 10 * MB;
+ header.class_defs_off_ = 10 * MB;
+ header.class_defs_size_ = 10000;
+ ASSERT_GE(writer.WriteBytes(&header, sizeof(header)), 0);
+ writer.FinishEntry();
+ writer.Finish();
+ ASSERT_EQ(invalid_dex.GetFile()->Flush(), 0);
+ }
+ const std::string dex_location = invalid_dex.GetFilename();
+ const std::string odex_location = GetOdexDir() + "/output.odex";
+ std::string error_msg;
+ int status = GenerateOdexForTestWithStatus(
+ {dex_location},
+ odex_location,
+ CompilerFilter::kQuicken,
+ &error_msg,
+ { "--compact-dex-level=fast" });
+ ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) != 0) << status << " " << output_;
+}
+
} // namespace art
diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
index 758a2f0599..1e0f5ac6ae 100644
--- a/libdexfile/dex/dex_file_loader.cc
+++ b/libdexfile/dex/dex_file_loader.cc
@@ -348,6 +348,8 @@ std::unique_ptr<DexFile> DexFileLoader::OpenCommon(const uint8_t* base,
location_checksum,
oat_dex_file,
std::move(container)));
+ // Disable verification for CompactDex input.
+ verify = false;
} else {
*error_msg = "Invalid or truncated dex file";
}