OSDN Git Service

Make <clinit> verification stronger for v37+.
authorAlex Light <allight@google.com>
Fri, 6 May 2016 17:39:06 +0000 (10:39 -0700)
committerAlex Light <allight@google.com>
Fri, 6 May 2016 21:31:25 +0000 (21:31 +0000)
Preserve the verification behavior of M for v35 dex files. v37+ get
stronger behavior

Bug: 28605638
Change-Id: If1ff4abcc61e0945f924fe4e10e173c03b4cd1a9

runtime/dex_file_verifier.cc

index 21ee4bd..c504074 100644 (file)
@@ -2609,7 +2609,13 @@ bool DexFileVerifier::CheckMethodAccessFlags(uint32_t method_index,
       *error_msg = StringPrintf("Constructor %" PRIu32 "(%s) is not flagged correctly wrt/ static.",
                                 method_index,
                                 GetMethodDescriptionOrError(begin_, header_, method_index).c_str());
-      return false;
+      if (header_->GetVersion() >= DexFile::kDefaultMethodsVersion) {
+        return false;
+      } else {
+        // Allow in older versions, but warn.
+        LOG(WARNING) << "This dex file is invalid and will be rejected in the future. Error is: "
+                     << *error_msg;
+      }
     }
   }
   // Check that static and private methods, as well as constructors, are in the direct methods list,
@@ -2663,7 +2669,13 @@ bool DexFileVerifier::CheckMethodAccessFlags(uint32_t method_index,
       *error_msg = StringPrintf("Constructor %u(%s) must not be abstract or native",
                                 method_index,
                                 GetMethodDescriptionOrError(begin_, header_, method_index).c_str());
-      return false;
+      if (header_->GetVersion() >= DexFile::kDefaultMethodsVersion) {
+        return false;
+      } else {
+        // Allow in older versions, but warn.
+        LOG(WARNING) << "This dex file is invalid and will be rejected in the future. Error is: "
+                      << *error_msg;
+      }
     }
     if ((method_access_flags & kAccAbstract) != 0) {
       // Abstract methods are not allowed to have the following flags.