Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d1fb44c authored by David Srbecky's avatar David Srbecky Committed by android-build-merger
Browse files

Merge "Fix in-memory loading of cdex files with shared data." am: d663ef97

am: 29379fa4

Change-Id: I3d1731b7c0e28e4a743d128785a88242721b294e
parents 8dadf1fd 29379fa4
Loading
Loading
Loading
Loading
+4 −5
Original line number Original line Diff line number Diff line
@@ -150,16 +150,18 @@ bool DexFileFromMemory::Open(uint64_t dex_file_offset_in_memory, Memory* memory)
  }
  }


  art::DexFile::Header* header = reinterpret_cast<art::DexFile::Header*>(memory_.data());
  art::DexFile::Header* header = reinterpret_cast<art::DexFile::Header*>(memory_.data());
  bool modify_data_off = false;
  uint32_t file_size = header->file_size_;
  uint32_t file_size = header->file_size_;
  if (art::CompactDexFile::IsMagicValid(header->magic_)) {
  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;
    uint32_t computed_file_size;
    if (__builtin_add_overflow(header->data_off_, header->data_size_, &computed_file_size)) {
    if (__builtin_add_overflow(header->data_off_, header->data_size_, &computed_file_size)) {
      return false;
      return false;
    }
    }
    if (computed_file_size > file_size) {
    if (computed_file_size > file_size) {
      file_size = computed_file_size;
      file_size = computed_file_size;
      modify_data_off = true;
    }
    }
  } else if (!art::StandardDexFile::IsMagicValid(header->magic_)) {
  } else if (!art::StandardDexFile::IsMagicValid(header->magic_)) {
    return false;
    return false;
@@ -171,9 +173,6 @@ bool DexFileFromMemory::Open(uint64_t dex_file_offset_in_memory, Memory* memory)
  }
  }


  header = reinterpret_cast<art::DexFile::Header*>(memory_.data());
  header = reinterpret_cast<art::DexFile::Header*>(memory_.data());
  if (modify_data_off) {
    header->data_off_ = header->file_size_;
  }


  art::DexFileLoader loader;
  art::DexFileLoader loader;
  std::string error_msg;
  std::string error_msg;