Fix possible overrun bug for resolving startup strings
Moved the ResolveConstStrings after verification and added logic to
only resolve strings for classes that verify. This fixes a bug
where invalid Dex bytecode could cause dex2oat to crash.
Bug: 128915540
Test: test-art-host
Change-Id: Id2e5e4b10e5afbb8955e805d199754bc255a2f42
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 520b455..bcd573b 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -690,6 +690,12 @@
profile_compilation_info != nullptr &&
profile_compilation_info->ContainsClass(*dex_file, accessor.GetClassIdx());
+ // Skip methods that failed to verify since they may contain invalid Dex code.
+ if (GetClassStatus(ClassReference(dex_file, accessor.GetClassDefIndex())) <
+ ClassStatus::kRetryVerificationAtRuntime) {
+ continue;
+ }
+
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
const bool is_clinit = (method.GetAccessFlags() & kAccConstructor) != 0 &&
(method.GetAccessFlags() & kAccStatic) != 0;
@@ -873,6 +879,9 @@
return;
}
+ Verify(class_loader, dex_files, timings, verification_results);
+ VLOG(compiler) << "Verify: " << GetMemoryUsageString(false);
+
if (GetCompilerOptions().IsForceDeterminism() && GetCompilerOptions().IsBootImage()) {
// Resolve strings from const-string. Do this now to have a deterministic image.
ResolveConstStrings(dex_files, /*only_startup_strings=*/ false, timings);
@@ -881,9 +890,6 @@
ResolveConstStrings(dex_files, /*only_startup_strings=*/ true, timings);
}
- Verify(class_loader, dex_files, timings, verification_results);
- VLOG(compiler) << "Verify: " << GetMemoryUsageString(false);
-
if (had_hard_verifier_failure_ && GetCompilerOptions().AbortOnHardVerifierFailure()) {
// Avoid dumping threads. Even if we shut down the thread pools, there will still be three
// instances of this thread's stack.