Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 801c4411 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[res] Properly create ZipAssetsProvider with fd

Bug: 237583012
Test: atest com.android.overlaytest
Change-Id: If79b4297edfcefe72bf579b50931a40f73bdfd58
parent 29764a29
Loading
Loading
Loading
Loading

libs/androidfw/ApkAssets.cpp

100755 → 100644
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "android-base/errors.h"
#include "android-base/logging.h"
#include "android-base/utf8.h"

namespace android {

@@ -84,7 +85,7 @@ std::unique_ptr<ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path,
  }

  std::string overlay_path(loaded_idmap->OverlayApkPath());
  auto fd = unique_fd(::open(overlay_path.c_str(), O_RDONLY|O_CLOEXEC));
  auto fd = unique_fd(base::utf8::open(overlay_path.c_str(), O_RDONLY | O_CLOEXEC));
  std::unique_ptr<AssetsProvider> overlay_assets;
  if (IsFabricatedOverlay(fd)) {
    // Fabricated overlays do not contain resource definitions. All of the overlay resource values
@@ -92,7 +93,7 @@ std::unique_ptr<ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path,
    overlay_assets = EmptyAssetsProvider::Create(std::move(overlay_path));
  } else {
    // The overlay should be an APK.
    overlay_assets = ZipAssetsProvider::Create(std::move(fd), std::move(overlay_path), flags);
    overlay_assets = ZipAssetsProvider::Create(std::move(overlay_path), flags, std::move(fd));
  }
  if (overlay_assets == nullptr) {
    return {};
+6 −3
Original line number Diff line number Diff line
@@ -92,16 +92,19 @@ ZipAssetsProvider::ZipAssetsProvider(ZipArchiveHandle handle, PathOrDebugName&&
      last_mod_time_(last_mod_time) {}

std::unique_ptr<ZipAssetsProvider> ZipAssetsProvider::Create(std::string path,
                                                             package_property_t flags) {
                                                             package_property_t flags,
                                                             base::unique_fd fd) {
  const auto released_fd = fd.ok() ? fd.release() : -1;
  ZipArchiveHandle handle;
  if (int32_t result = OpenArchive(path.c_str(), &handle); result != 0) {
  if (int32_t result = released_fd < 0 ? OpenArchive(path.c_str(), &handle)
                                       : OpenArchiveFd(released_fd, path.c_str(), &handle)) {
    LOG(ERROR) << "Failed to open APK '" << path << "': " << ::ErrorCodeString(result);
    CloseArchive(handle);
    return {};
  }

  struct stat sb{.st_mtime = -1};
  if (stat(path.c_str(), &sb) < 0) {
  if ((released_fd < 0 ? stat(path.c_str(), &sb) : fstat(released_fd, &sb)) < 0) {
    // Stat requires execute permissions on all directories path to the file. If the process does
    // not have execute permissions on this file, allow the zip to be opened but IsUpToDate() will
    // always have to return true.
+2 −2
Original line number Diff line number Diff line
@@ -80,8 +80,8 @@ struct AssetsProvider {

// Supplies assets from a zip archive.
struct ZipAssetsProvider : public AssetsProvider {
  static std::unique_ptr<ZipAssetsProvider> Create(std::string path,
                                                   package_property_t flags);
  static std::unique_ptr<ZipAssetsProvider> Create(std::string path, package_property_t flags,
                                                   base::unique_fd fd = {});

  static std::unique_ptr<ZipAssetsProvider> Create(base::unique_fd fd,
                                                   std::string friendly_name,