Loading libs/androidfw/ApkAssets.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -83,15 +83,16 @@ std::unique_ptr<ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path, return {}; } std::string overlay_path(loaded_idmap->OverlayApkPath()); auto fd = unique_fd(::open(overlay_path.c_str(), O_RDONLY|O_CLOEXEC)); std::unique_ptr<AssetsProvider> overlay_assets; const std::string overlay_path(loaded_idmap->OverlayApkPath()); if (IsFabricatedOverlay(overlay_path)) { if (IsFabricatedOverlay(fd)) { // Fabricated overlays do not contain resource definitions. All of the overlay resource values // are defined inline in the idmap. overlay_assets = EmptyAssetsProvider::Create(overlay_path); overlay_assets = EmptyAssetsProvider::Create(std::move(overlay_path)); } else { // The overlay should be an APK. overlay_assets = ZipAssetsProvider::Create(overlay_path, flags); overlay_assets = ZipAssetsProvider::Create(std::move(fd), std::move(overlay_path), flags); } if (overlay_assets == nullptr) { return {}; Loading libs/androidfw/AssetsProvider.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -393,8 +393,8 @@ std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create() { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider({})); } std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create(const std::string& path) { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider(path)); std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create(std::string path) { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider(std::move(path))); } std::unique_ptr<Asset> EmptyAssetsProvider::OpenInternal(const std::string& /* path */, Loading libs/androidfw/ResourceTypes.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ #include <type_traits> #include <vector> #include <android-base/file.h> #include <android-base/macros.h> #include <android-base/utf8.h> #include <androidfw/ByteBucketArray.h> #include <androidfw/ResourceTypes.h> #include <androidfw/TypeWrappers.h> Loading Loading @@ -236,13 +238,24 @@ void Res_png_9patch::serialize(const Res_png_9patch& patch, const int32_t* xDivs } bool IsFabricatedOverlay(const std::string& path) { std::ifstream fin(path); uint32_t magic; if (fin.read(reinterpret_cast<char*>(&magic), sizeof(uint32_t))) { return magic == kFabricatedOverlayMagic; return IsFabricatedOverlay(path.c_str()); } bool IsFabricatedOverlay(const char* path) { auto fd = base::unique_fd(base::utf8::open(path, O_RDONLY|O_CLOEXEC)); if (fd < 0) { return false; } return IsFabricatedOverlay(fd); } bool IsFabricatedOverlay(base::borrowed_fd fd) { uint32_t magic; if (!base::ReadFullyAtOffset(fd, &magic, sizeof(magic), 0)) { return false; } return magic == kFabricatedOverlayMagic; } static bool assertIdmapHeader(const void* idmap, size_t size) { if (reinterpret_cast<uintptr_t>(idmap) & 0x03) { Loading libs/androidfw/include/androidfw/AssetsProvider.h +1 −1 Original line number Diff line number Diff line Loading @@ -181,7 +181,7 @@ struct MultiAssetsProvider : public AssetsProvider { // Does not provide any assets. struct EmptyAssetsProvider : public AssetsProvider { static std::unique_ptr<AssetsProvider> Create(); static std::unique_ptr<AssetsProvider> Create(const std::string& path); static std::unique_ptr<AssetsProvider> Create(std::string path); bool ForEachFile(const std::string& path, const std::function<void(StringPiece, FileType)>& f) const override; Loading libs/androidfw/include/androidfw/ResourceTypes.h +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #define _LIBS_UTILS_RESOURCE_TYPES_H #include <android-base/expected.h> #include <android-base/unique_fd.h> #include <androidfw/Asset.h> #include <androidfw/Errors.h> Loading Loading @@ -58,6 +59,8 @@ constexpr const uint32_t kFabricatedOverlayCurrentVersion = 3; // Returns whether or not the path represents a fabricated overlay. bool IsFabricatedOverlay(const std::string& path); bool IsFabricatedOverlay(const char* path); bool IsFabricatedOverlay(android::base::borrowed_fd fd); /** * In C++11, char16_t is defined as *at least* 16 bits. We do a lot of Loading Loading
libs/androidfw/ApkAssets.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -83,15 +83,16 @@ std::unique_ptr<ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path, return {}; } std::string overlay_path(loaded_idmap->OverlayApkPath()); auto fd = unique_fd(::open(overlay_path.c_str(), O_RDONLY|O_CLOEXEC)); std::unique_ptr<AssetsProvider> overlay_assets; const std::string overlay_path(loaded_idmap->OverlayApkPath()); if (IsFabricatedOverlay(overlay_path)) { if (IsFabricatedOverlay(fd)) { // Fabricated overlays do not contain resource definitions. All of the overlay resource values // are defined inline in the idmap. overlay_assets = EmptyAssetsProvider::Create(overlay_path); overlay_assets = EmptyAssetsProvider::Create(std::move(overlay_path)); } else { // The overlay should be an APK. overlay_assets = ZipAssetsProvider::Create(overlay_path, flags); overlay_assets = ZipAssetsProvider::Create(std::move(fd), std::move(overlay_path), flags); } if (overlay_assets == nullptr) { return {}; Loading
libs/androidfw/AssetsProvider.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -393,8 +393,8 @@ std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create() { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider({})); } std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create(const std::string& path) { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider(path)); std::unique_ptr<AssetsProvider> EmptyAssetsProvider::Create(std::string path) { return std::unique_ptr<EmptyAssetsProvider>(new EmptyAssetsProvider(std::move(path))); } std::unique_ptr<Asset> EmptyAssetsProvider::OpenInternal(const std::string& /* path */, Loading
libs/androidfw/ResourceTypes.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ #include <type_traits> #include <vector> #include <android-base/file.h> #include <android-base/macros.h> #include <android-base/utf8.h> #include <androidfw/ByteBucketArray.h> #include <androidfw/ResourceTypes.h> #include <androidfw/TypeWrappers.h> Loading Loading @@ -236,13 +238,24 @@ void Res_png_9patch::serialize(const Res_png_9patch& patch, const int32_t* xDivs } bool IsFabricatedOverlay(const std::string& path) { std::ifstream fin(path); uint32_t magic; if (fin.read(reinterpret_cast<char*>(&magic), sizeof(uint32_t))) { return magic == kFabricatedOverlayMagic; return IsFabricatedOverlay(path.c_str()); } bool IsFabricatedOverlay(const char* path) { auto fd = base::unique_fd(base::utf8::open(path, O_RDONLY|O_CLOEXEC)); if (fd < 0) { return false; } return IsFabricatedOverlay(fd); } bool IsFabricatedOverlay(base::borrowed_fd fd) { uint32_t magic; if (!base::ReadFullyAtOffset(fd, &magic, sizeof(magic), 0)) { return false; } return magic == kFabricatedOverlayMagic; } static bool assertIdmapHeader(const void* idmap, size_t size) { if (reinterpret_cast<uintptr_t>(idmap) & 0x03) { Loading
libs/androidfw/include/androidfw/AssetsProvider.h +1 −1 Original line number Diff line number Diff line Loading @@ -181,7 +181,7 @@ struct MultiAssetsProvider : public AssetsProvider { // Does not provide any assets. struct EmptyAssetsProvider : public AssetsProvider { static std::unique_ptr<AssetsProvider> Create(); static std::unique_ptr<AssetsProvider> Create(const std::string& path); static std::unique_ptr<AssetsProvider> Create(std::string path); bool ForEachFile(const std::string& path, const std::function<void(StringPiece, FileType)>& f) const override; Loading
libs/androidfw/include/androidfw/ResourceTypes.h +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #define _LIBS_UTILS_RESOURCE_TYPES_H #include <android-base/expected.h> #include <android-base/unique_fd.h> #include <androidfw/Asset.h> #include <androidfw/Errors.h> Loading Loading @@ -58,6 +59,8 @@ constexpr const uint32_t kFabricatedOverlayCurrentVersion = 3; // Returns whether or not the path represents a fabricated overlay. bool IsFabricatedOverlay(const std::string& path); bool IsFabricatedOverlay(const char* path); bool IsFabricatedOverlay(android::base::borrowed_fd fd); /** * In C++11, char16_t is defined as *at least* 16 bits. We do a lot of Loading