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:37:17 +0000 (14:37 -0700)
Preserve the verification behavior of M for v35 dex files. v37+ get
stronger behavior

Bug: 28605638
Change-Id: If1ff4abcc61e0945f924fe4e10e173c03b4cd1a9
(cherry picked from commit f0ecae7730b6c0145e0176cc619bdfba48201105)

runtime/dex_file_verifier.cc

index 3df4e98..7006033 100644 (file)
@@ -2608,7 +2608,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,
@@ -2662,7 +2668,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.