Fix checksum verification when opening DexFiles from OatFiles
Change-Id: Ic3d13f3d591c34f159bf0739536a1751c3e7dc75
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index 94281c9..e4c8135 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -680,7 +680,7 @@
const std::string& location(dex_file.GetLocation());
dex_file_location_size_ = location.size();
dex_file_location_data_ = reinterpret_cast<const uint8_t*>(location.data());
- dex_file_checksum_ = dex_file.GetHeader().checksum_;
+ dex_file_location_checksum_ = dex_file.GetLocationChecksum();
dex_file_offset_ = 0;
methods_offsets_.resize(dex_file.NumClassDefs());
}
@@ -688,7 +688,7 @@
size_t OatWriter::OatDexFile::SizeOf() const {
return sizeof(dex_file_location_size_)
+ dex_file_location_size_
- + sizeof(dex_file_checksum_)
+ + sizeof(dex_file_location_checksum_)
+ sizeof(dex_file_offset_)
+ (sizeof(methods_offsets_[0]) * methods_offsets_.size());
}
@@ -696,7 +696,7 @@
void OatWriter::OatDexFile::UpdateChecksum(OatHeader& oat_header) const {
oat_header.UpdateChecksum(&dex_file_location_size_, sizeof(dex_file_location_size_));
oat_header.UpdateChecksum(dex_file_location_data_, dex_file_location_size_);
- oat_header.UpdateChecksum(&dex_file_checksum_, sizeof(dex_file_checksum_));
+ oat_header.UpdateChecksum(&dex_file_location_checksum_, sizeof(dex_file_location_checksum_));
oat_header.UpdateChecksum(&dex_file_offset_, sizeof(dex_file_offset_));
oat_header.UpdateChecksum(&methods_offsets_[0],
sizeof(methods_offsets_[0]) * methods_offsets_.size());
@@ -711,8 +711,8 @@
PLOG(ERROR) << "Failed to write dex file location data to " << file->name();
return false;
}
- if (!file->WriteFully(&dex_file_checksum_, sizeof(dex_file_checksum_))) {
- PLOG(ERROR) << "Failed to write dex file checksum to " << file->name();
+ if (!file->WriteFully(&dex_file_location_checksum_, sizeof(dex_file_location_checksum_))) {
+ PLOG(ERROR) << "Failed to write dex file location checksum to " << file->name();
return false;
}
if (!file->WriteFully(&dex_file_offset_, sizeof(dex_file_offset_))) {