From 417f7c3720d88ae7993615c7d20e9d1a4e1d12ee Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Mon, 5 Feb 2018 20:14:48 +0000 Subject: [PATCH] Fix in-memory loading of cdex files with shared data. Several cdex files may share the same data for de-duplication. Bug: 72520014 Test: Disable DexFileFromFile and then run ART's 137 test. Change-Id: Icfe04255cc20a302f844c2e3e3016578856e1f82 --- libunwindstack/DexFile.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp index b4a992a89..c2911df5b 100644 --- a/libunwindstack/DexFile.cpp +++ b/libunwindstack/DexFile.cpp @@ -150,16 +150,18 @@ bool DexFileFromMemory::Open(uint64_t dex_file_offset_in_memory, Memory* memory) } art::DexFile::Header* header = reinterpret_cast(memory_.data()); - bool modify_data_off = false; uint32_t file_size = header->file_size_; if (art::CompactDexFile::IsMagicValid(header->magic_)) { + // Compact dex file store data section separately so that it can be shared. + // Therefore we need to extend the read memory range to include it. + // TODO: This might be wasteful as we might read data in between as well. + // In practice, this should be fine, as such sharing only happens on disk. uint32_t computed_file_size; if (__builtin_add_overflow(header->data_off_, header->data_size_, &computed_file_size)) { return false; } if (computed_file_size > file_size) { file_size = computed_file_size; - modify_data_off = true; } } else if (!art::StandardDexFile::IsMagicValid(header->magic_)) { return false; @@ -171,9 +173,6 @@ bool DexFileFromMemory::Open(uint64_t dex_file_offset_in_memory, Memory* memory) } header = reinterpret_cast(memory_.data()); - if (modify_data_off) { - header->data_off_ = header->file_size_; - } art::DexFileLoader loader; std::string error_msg;