diff options
author | Brian Carlstrom <bdc@google.com> | 2013-07-25 22:00:16 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-07-26 00:00:53 -0700 |
commit | fb331d7ca004f39608fcfdae49d38df90c702ea9 (patch) | |
tree | f6e38cf1104bb68291507f2ebe49b2d921f76d08 /runtime | |
parent | 0de7985b29257bb60be511db774a4f0119a81f20 (diff) | |
download | android_art-fb331d7ca004f39608fcfdae49d38df90c702ea9.tar.gz android_art-fb331d7ca004f39608fcfdae49d38df90c702ea9.tar.bz2 android_art-fb331d7ca004f39608fcfdae49d38df90c702ea9.zip |
Convert CHECKS in OatFile::Setup to LOG(ERROR) messages
Bug: 10018504
Change-Id: I4d63d8920951a2ef996a98d2b248a1144f981fde
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/oat_file.cc | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 6562633bc3..7bffc8cd52 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -197,46 +197,98 @@ bool OatFile::Setup() { } const byte* oat = Begin(); oat += sizeof(OatHeader); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found truncated OatHeader"; + return false; + } + oat += GetOatHeader().GetImageFileLocationSize(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found truncated image file location: " + << reinterpret_cast<const void*>(Begin()) + << "+" << sizeof(OatHeader) + << "+" << GetOatHeader().GetImageFileLocationSize() + << "<=" << reinterpret_cast<const void*>(End()); + return false; + } - CHECK_LE(oat, End()) - << reinterpret_cast<const void*>(Begin()) - << "+" << sizeof(OatHeader) - << "+" << GetOatHeader().GetImageFileLocationSize() - << "<=" << reinterpret_cast<const void*>(End()) - << " " << GetLocation(); for (size_t i = 0; i < GetOatHeader().GetDexFileCount(); i++) { size_t dex_file_location_size = *reinterpret_cast<const uint32_t*>(oat); - CHECK_GT(dex_file_location_size, 0U) << GetLocation(); + if (dex_file_location_size == 0U) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " with empty location name"; + return false; + } oat += sizeof(dex_file_location_size); - CHECK_LT(oat, End()) << GetLocation(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " truncated after dex file location size"; + return false; + } const char* dex_file_location_data = reinterpret_cast<const char*>(oat); oat += dex_file_location_size; - CHECK_LT(oat, End()) << GetLocation(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " with truncated dex file location"; + return false; + } std::string dex_file_location(dex_file_location_data, dex_file_location_size); uint32_t dex_file_checksum = *reinterpret_cast<const uint32_t*>(oat); oat += sizeof(dex_file_checksum); - CHECK_LT(oat, End()) << GetLocation(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " truncated after dex file checksum"; + return false; + } uint32_t dex_file_offset = *reinterpret_cast<const uint32_t*>(oat); - CHECK_GT(dex_file_offset, 0U) << GetLocation(); - CHECK_LT(dex_file_offset, Size()) << GetLocation(); + if (dex_file_offset == 0U) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " with zero dex file offset"; + return false; + } + if (dex_file_offset > Size()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " with dex file offset" << dex_file_offset << " > " << Size(); + return false; + } oat += sizeof(dex_file_offset); - CHECK_LT(oat, End()) << GetLocation(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " truncated after dex file offset"; + return false; + } const uint8_t* dex_file_pointer = Begin() + dex_file_offset; - CHECK(DexFile::IsMagicValid(dex_file_pointer)) - << GetLocation() << " " << dex_file_pointer; - CHECK(DexFile::IsVersionValid(dex_file_pointer)) - << GetLocation() << " " << dex_file_pointer; + if (!DexFile::IsMagicValid(dex_file_pointer)) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " with invalid dex file magic: " << dex_file_pointer; + return false; + } + if (!DexFile::IsVersionValid(dex_file_pointer)) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " with invalid dex file version: " << dex_file_pointer; + return false; + } const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer); const uint32_t* methods_offsets_pointer = reinterpret_cast<const uint32_t*>(oat); oat += (sizeof(*methods_offsets_pointer) * header->class_defs_size_); - CHECK_LE(oat, End()) << GetLocation(); + if (oat > End()) { + LOG(ERROR) << "In oat file " << GetLocation() << " found OatDexFile # " << i + << " for "<< dex_file_location + << " with truncated method offsets"; + return false; + } oat_dex_files_.Put(dex_file_location, new OatDexFile(this, dex_file_location, @@ -361,10 +413,12 @@ OatFile::OatMethod::OatMethod(const byte* base, #ifndef NDEBUG if (mapping_table_offset_ != 0) { // implies non-native, non-stub code if (vmap_table_offset_ == 0) { - DCHECK_EQ(0U, static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + __builtin_popcount(fp_spill_mask_))); + DCHECK_EQ(0U, static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + + __builtin_popcount(fp_spill_mask_))); } else { const uint16_t* vmap_table_ = reinterpret_cast<const uint16_t*>(begin_ + vmap_table_offset_); - DCHECK_EQ(vmap_table_[0], static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + __builtin_popcount(fp_spill_mask_))); + DCHECK_EQ(vmap_table_[0], static_cast<uint32_t>(__builtin_popcount(core_spill_mask_) + + __builtin_popcount(fp_spill_mask_))); } } else { DCHECK_EQ(vmap_table_offset_, 0U); @@ -405,7 +459,7 @@ void OatFile::OatMethod::LinkMethod(mirror::AbstractMethod* method) const { method->SetFpSpillMask(fp_spill_mask_); method->SetMappingTable(GetMappingTable()); method->SetVmapTable(GetVmapTable()); - method->SetNativeGcMap(GetNativeGcMap()); // Note, used by native methods in work around JNI mode. + method->SetNativeGcMap(GetNativeGcMap()); // Used by native methods in work around JNI mode. } } // namespace art |