Use file magic to determine file type, not file extension.
Bug: 10614658
Change-Id: I9156dfca78ac8cd1c62fb258825cc791629270a4
diff --git a/runtime/utils.cc b/runtime/utils.cc
index dcfe8a7..8e810a7 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -1196,7 +1196,7 @@
LOG(FATAL) << "Expected path in location to be absolute: "<< location;
}
std::string cache_file(location, 1); // skip leading slash
- if (!IsValidDexFilename(location) && !IsValidImageFilename(location)) {
+ if (!EndsWith(location, ".dex") || !EndsWith(location, ".art")) {
cache_file += "/";
cache_file += DexFile::kClassesDex;
}
@@ -1204,27 +1204,19 @@
return dalvik_cache + "/" + cache_file;
}
-bool IsValidZipFilename(const std::string& filename) {
- if (filename.size() < 4) {
- return false;
- }
- std::string suffix(filename.substr(filename.size() - 4));
- return (suffix == ".zip" || suffix == ".jar" || suffix == ".apk");
+bool IsZipMagic(uint32_t magic) {
+ return (('P' == ((magic >> 0) & 0xff)) &&
+ ('K' == ((magic >> 8) & 0xff)));
}
-bool IsValidDexFilename(const std::string& filename) {
- return EndsWith(filename, ".dex");
+bool IsDexMagic(uint32_t magic) {
+ return DexFile::IsMagicValid(reinterpret_cast<const byte*>(&magic));
}
-bool IsValidImageFilename(const std::string& filename) {
- return EndsWith(filename, ".art");
-}
-
-bool IsValidOatFilename(const std::string& filename) {
- return (EndsWith(filename, ".odex") ||
- EndsWith(filename, ".dex") ||
- EndsWith(filename, ".oat") ||
- EndsWith(filename, DexFile::kClassesDex));
+bool IsOatMagic(uint32_t magic) {
+ return (memcmp(reinterpret_cast<const byte*>(magic),
+ OatHeader::kOatMagic,
+ sizeof(OatHeader::kOatMagic)) == 0);
}
} // namespace art