From 0cba004b97245300d7f39318d5921ee8edbef1ac Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Wed, 29 Apr 2015 20:47:16 -0700 Subject: ART: Allow oat files with duplicates classes in corner case When the oat file is actually an odex file, that is, a preopted /system app, then it is impossible to fall back to the original APK, as that has been stripped. When it looks like it will be impossible to successfully open the original dex location, grudgingly allow to open the found oat file, even if it has duplicate classes, but warn accordingly. Bug: 20697582 Change-Id: I1dd459563d977a2e77806eacd03e49334d5b1f14 --- runtime/dex_file.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'runtime/dex_file.cc') diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index 20098e7482..dfe5a04d8f 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -153,6 +153,31 @@ bool DexFile::Open(const char* filename, const char* location, std::string* erro return false; } +static bool ContainsClassesDex(int fd, const char* filename) { + std::string error_msg; + std::unique_ptr zip_archive(ZipArchive::OpenFromFd(fd, filename, &error_msg)); + if (zip_archive.get() == nullptr) { + return false; + } + std::unique_ptr zip_entry(zip_archive->Find(DexFile::kClassesDex, &error_msg)); + return (zip_entry.get() != nullptr); +} + +bool DexFile::MaybeDex(const char* filename) { + uint32_t magic; + std::string error_msg; + ScopedFd fd(OpenAndReadMagic(filename, &magic, &error_msg)); + if (fd.get() == -1) { + return false; + } + if (IsZipMagic(magic)) { + return ContainsClassesDex(fd.release(), filename); + } else if (IsDexMagic(magic)) { + return true; + } + return false; +} + int DexFile::GetPermissions() const { if (mem_map_.get() == nullptr) { return 0; -- cgit v1.2.3-59-g8ed1b