Do not continue loading a vdex if we don't have enough reserved space.
It's always a sign that something is off and the oat file should be
rejected.
Note that if we continue loading, and the oat file somehow does not get
rejected, we will end up in a bogus situation where the OatFile has a
wrong value for vdex_begin_ and vdex_end_.
Test: test.py
Bug: 211367695
Change-Id: I6d6db4bc35f103c2aa935e91b2d329974cbd2d6b
diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc
index 8663d8b..b0ff362 100644
--- a/dex2oat/linker/oat_writer_test.cc
+++ b/dex2oat/linker/oat_writer_test.cc
@@ -203,6 +203,9 @@
return false;
}
oat_writer.Initialize(compiler_driver_.get(), /*image_writer=*/ nullptr, dex_files);
+ if (!oat_writer.FinishVdexFile(vdex_file, /*verifier_deps=*/ nullptr)) {
+ return false;
+ }
oat_writer.PrepareLayout(&patcher);
elf_writer->PrepareDynamicSection(oat_writer.GetOatHeader().GetExecutableOffset(),
oat_writer.GetCodeSize(),
@@ -212,9 +215,6 @@
oat_writer.GetBssRootsOffset(),
oat_writer.GetVdexSize());
- if (!oat_writer.FinishVdexFile(vdex_file, /*verifier_deps=*/ nullptr)) {
- return false;
- }
if (!oat_writer.WriteRodata(oat_rodata)) {
return false;
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index 0afa131..1bf6493 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -23,6 +23,7 @@
#include <unordered_set>
#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <log/log.h>
#include "base/bit_utils.h"
@@ -46,6 +47,8 @@
namespace art {
+using android::base::StringPrintf;
+
constexpr uint8_t VdexFile::VdexFileHeader::kVdexInvalidMagic[4];
constexpr uint8_t VdexFile::VdexFileHeader::kVdexMagic[4];
constexpr uint8_t VdexFile::VdexFileHeader::kVdexVersion[4];
@@ -121,9 +124,10 @@
bool unquicken,
std::string* error_msg) {
if (mmap_addr != nullptr && mmap_size < vdex_length) {
- LOG(WARNING) << "Insufficient pre-allocated space to mmap vdex.";
- mmap_addr = nullptr;
- mmap_reuse = false;
+ *error_msg = StringPrintf("Insufficient pre-allocated space to mmap vdex: %zu and %zu",
+ mmap_size,
+ vdex_length);
+ return nullptr;
}
CHECK(!mmap_reuse || mmap_addr != nullptr);
CHECK(!(writable && unquicken)) << "We don't want to be writing unquickened files out to disk!";