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

Commit bfe4b5ed authored by Narayan Kamath's avatar Narayan Kamath
Browse files

DO NOT MERGE : Partially revert change 141d1d836465e8a5a56a5cc1e.

There are no functional changes here. This is in place to make merge
conflicts less likely if any further changes are made to this code in
the future.

Test: make
Test: zip_archive_test
Bug: 64211847

Change-Id: I80ff9712c85d602d27f132ac54f62b3524ac9106
parent 547c7d9a
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -594,28 +594,7 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name,
  return result;
}

// Attempts to read |len| bytes into |buf| at offset |off|.
//
// This method uses pread64 on platforms that support it and
// lseek64 + read on platforms that don't. This implies that
// callers should not rely on the |fd| offset being incremented
// as a side effect of this call.
static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len,
                                   off64_t off) {
#ifdef HAVE_PREAD
  return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off));
#else
  // The only supported platform that doesn't support pread at the moment
  // is Windows. Only recent versions of windows support unix like forks,
  // and even there the semantics are quite different.
  if (lseek64(fd, off, SEEK_SET) != off) {
    ALOGW("Zip: failed seek to offset %" PRId64, off);
    return kIoError;
  }

  return TEMP_FAILURE_RETRY(read(fd, buf, len));
#endif  // HAVE_PREAD
}
static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, off64_t off);

/*
 * Parses the Zip archive's Central Directory.  Allocates and populates the
@@ -778,6 +757,29 @@ static int32_t UpdateEntryFromDataDescriptor(int fd,
  return 0;
}

// Attempts to read |len| bytes into |buf| at offset |off|.
//
// This method uses pread64 on platforms that support it and
// lseek64 + read on platforms that don't. This implies that
// callers should not rely on the |fd| offset being incremented
// as a side effect of this call.
static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len,
                                   off64_t off) {
#ifdef HAVE_PREAD
  return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off));
#else
  // The only supported platform that doesn't support pread at the moment
  // is Windows. Only recent versions of windows support unix like forks,
  // and even there the semantics are quite different.
  if (lseek64(fd, off, SEEK_SET) != off) {
    ALOGW("Zip: failed seek to offset %" PRId64, off);
    return kIoError;
  }

  return TEMP_FAILURE_RETRY(read(fd, buf, len));
#endif  // HAVE_PREAD
}

static int32_t FindEntry(const ZipArchive* archive, const int ent,
                         ZipEntry* data) {
  const uint16_t nameLen = archive->hash_table[ent].name_length;