diff options
| -rw-r--r-- | compiler/driver/compiler_driver.cc | 1 | ||||
| -rw-r--r-- | dex2oat/dex2oat_test.cc | 47 | ||||
| -rw-r--r-- | openjdkjvmti/ti_stack.cc | 4 | ||||
| -rw-r--r-- | runtime/class_linker.cc | 2 | ||||
| -rw-r--r-- | runtime/class_linker.h | 2 | ||||
| -rw-r--r-- | runtime/dex/art_dex_file_loader.cc | 17 |
6 files changed, 70 insertions, 3 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index bd3a145368..53604761d1 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -2317,6 +2317,7 @@ class InitializeClassVisitor : public CompilationVisitor { // The boot image case doesn't need to recursively initialize the dependencies with // special logic since the class linker already does this. can_init_static_fields = + ClassLinker::kAppImageMayContainStrings && !soa.Self()->IsExceptionPending() && is_superclass_initialized && NoClinitInDependency(klass, soa.Self(), &class_loader); diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc index 5e9782aadf..0cd39ac11b 100644 --- a/dex2oat/dex2oat_test.cc +++ b/dex2oat/dex2oat_test.cc @@ -2046,4 +2046,51 @@ TEST_F(Dex2oatTest, CompactDexInvalidSource) { ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) != 0) << status << " " << output_; } +// Test that dex2oat with a CompactDex file in the APK fails. +TEST_F(Dex2oatTest, CompactDexInZip) { + CompactDexFile::Header header = {}; + CompactDexFile::WriteMagic(header.magic_); + CompactDexFile::WriteCurrentVersion(header.magic_); + header.file_size_ = sizeof(CompactDexFile::Header); + header.data_off_ = 10 * MB; + header.map_off_ = 10 * MB; + header.class_defs_off_ = 10 * MB; + header.class_defs_size_ = 10000; + // Create a zip containing the invalid dex. + ScratchFile invalid_dex_zip; + { + FILE* file = fdopen(invalid_dex_zip.GetFd(), "w+b"); + ZipWriter writer(file); + writer.StartEntry("classes.dex", ZipWriter::kCompress); + ASSERT_GE(writer.WriteBytes(&header, sizeof(header)), 0); + writer.FinishEntry(); + writer.Finish(); + ASSERT_EQ(invalid_dex_zip.GetFile()->Flush(), 0); + } + // Create the dex file directly. + ScratchFile invalid_dex; + { + ASSERT_GE(invalid_dex.GetFile()->WriteFully(&header, sizeof(header)), 0); + ASSERT_EQ(invalid_dex.GetFile()->Flush(), 0); + } + std::string error_msg; + int status = 0u; + + status = GenerateOdexForTestWithStatus( + { invalid_dex_zip.GetFilename() }, + GetOdexDir() + "/output_apk.odex", + CompilerFilter::kQuicken, + &error_msg, + { "--compact-dex-level=fast" }); + ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) != 0) << status << " " << output_; + + status = GenerateOdexForTestWithStatus( + { invalid_dex.GetFilename() }, + GetOdexDir() + "/output.odex", + CompilerFilter::kQuicken, + &error_msg, + { "--compact-dex-level=fast" }); + ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) != 0) << status << " " << output_; +} + } // namespace art diff --git a/openjdkjvmti/ti_stack.cc b/openjdkjvmti/ti_stack.cc index 373944f179..b96374d43a 100644 --- a/openjdkjvmti/ti_stack.cc +++ b/openjdkjvmti/ti_stack.cc @@ -484,7 +484,7 @@ jvmtiError StackUtil::GetThreadListStackTraces(jvmtiEnv* env, *stack_info_ptr = nullptr; return ERR(NONE); } - if (stack_info_ptr == nullptr || stack_info_ptr == nullptr) { + if (thread_list == nullptr || stack_info_ptr == nullptr) { return ERR(NULL_POINTER); } @@ -971,7 +971,7 @@ jvmtiError StackUtil::GetOwnedMonitorInfo(jvmtiEnv* env, jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) { - if (owned_monitors_ptr == nullptr || owned_monitors_ptr == nullptr) { + if (owned_monitor_count_ptr == nullptr || owned_monitors_ptr == nullptr) { return ERR(NULL_POINTER); } auto handle_fun = [&] (art::ScopedObjectAccess& soa, MonitorVisitor& visitor) diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index f03e4cdb5d..e4a29c330c 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1343,7 +1343,7 @@ void AppImageClassLoadersAndDexCachesHelper::Update( } } } - { + if (ClassLinker::kAppImageMayContainStrings) { // Fixup all the literal strings happens at app images which are supposed to be interned. ScopedTrace timing("Fixup String Intern in image and dex_cache"); const auto& image_header = space->GetImageHeader(); diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 8ab3f72c1b..2471f146aa 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -152,6 +152,8 @@ class ClassLinker { kClassRootsMax, }; + static constexpr bool kAppImageMayContainStrings = false; + explicit ClassLinker(InternTable* intern_table); virtual ~ClassLinker(); diff --git a/runtime/dex/art_dex_file_loader.cc b/runtime/dex/art_dex_file_loader.cc index c456764834..9802c6904b 100644 --- a/runtime/dex/art_dex_file_loader.cc +++ b/runtime/dex/art_dex_file_loader.cc @@ -205,6 +205,12 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::Open(const std::string& locatio error_msg, std::make_unique<MemMapContainer>(std::move(map)), /*verify_result*/ nullptr); + // Opening CompactDex is only supported from vdex files. + if (dex_file != nullptr && dex_file->IsCompactDexFile()) { + *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files", + location.c_str()); + return nullptr; + } return dex_file; } @@ -329,6 +335,12 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::OpenFile(int fd, std::make_unique<MemMapContainer>(std::move(map)), /*verify_result*/ nullptr); + // Opening CompactDex is only supported from vdex files. + if (dex_file != nullptr && dex_file->IsCompactDexFile()) { + *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files", + location.c_str()); + return nullptr; + } return dex_file; } @@ -397,6 +409,11 @@ std::unique_ptr<const DexFile> ArtDexFileLoader::OpenOneDexFileFromZip( error_msg, std::make_unique<MemMapContainer>(std::move(map)), &verify_result); + if (dex_file != nullptr && dex_file->IsCompactDexFile()) { + *error_msg = StringPrintf("Opening CompactDex file '%s' is only supported from vdex files", + location.c_str()); + return nullptr; + } if (dex_file == nullptr) { if (verify_result == VerifyResult::kVerifyNotAttempted) { *error_code = ZipOpenErrorCode::kDexFileError; |