Fix potential null read for truncated dex files
In the case where a dex file is truncated, don't attempt to read the
header.
Added regression test.
Bug: 63756964
Bug: 72826975
Test: mm test-art-host-gtest-dex2oat_test -j64
Test: mm test-art-target-gtest-dex2oat_test -j64
Change-Id: I9bd6bb445ef2eb1c961044f43ac71f04ef8c04a5
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 5614ac6..17a27f8 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1543,4 +1543,20 @@
});
}
+TEST_F(Dex2oatTest, EmptyUncompressedDexTest) {
+ std::string out_dir = GetScratchDir();
+ const std::string base_oat_name = out_dir + "/base.oat";
+ std::string error_msg;
+ int status = GenerateOdexForTestWithStatus(
+ { GetTestDexFileName("MainEmptyUncompressed") },
+ base_oat_name,
+ CompilerFilter::Filter::kQuicken,
+ &error_msg,
+ { },
+ /*use_fd*/ false);
+ // Expect to fail with code 1 and not SIGSEGV or SIGABRT.
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 1) << error_msg;
+}
+
} // namespace art