From 9ff846053a33db95fcf739831baf55eb7e1ce243 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Fri, 29 Jan 2016 12:22:17 -0800 Subject: [PATCH] Add oat checksum check for app image loading Bug: 26846419 Bug: 22858531 Change-Id: If30028b7d6b5749f5bdbed0c219d014a3b50a11b --- runtime/gc/space/image_space.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index f6079232b..998db5271 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -1167,6 +1167,20 @@ ImageSpace* ImageSpace::Init(const char* image_filename, return nullptr; } + if (oat_file != nullptr) { + // If we have an oat file, check the oat file checksum. The oat file is only non-null for the + // app image case. Otherwise, we open the oat file after the image and check the checksum there. + const uint32_t oat_checksum = oat_file->GetOatHeader().GetChecksum(); + const uint32_t image_oat_checksum = image_header->GetOatChecksum(); + if (oat_checksum != image_oat_checksum) { + *error_msg = StringPrintf("Oat checksum 0x%x does not match the image one 0x%x in image %s", + oat_checksum, + image_oat_checksum, + image_filename); + return nullptr; + } + } + if (VLOG_IS_ON(startup)) { LOG(INFO) << "Dumping image sections"; for (size_t i = 0; i < ImageHeader::kSectionCount; ++i) { -- 2.11.0