diff options
author | Narayan Kamath | 2017-09-20 10:04:26 -0500 |
---|---|---|
committer | Narayan Kamath | 2017-09-20 10:07:06 -0500 |
commit | bfe4b5edb3097df66ddbf9639c3b3cd290734ed8 (patch) | |
tree | 7d3425717b08097add6ef2153b20d54e5cb0ad25 | |
parent | 547c7d9a0b6651ace0ade7849661ba6c20770ae6 (diff) | |
download | platform-system-core-bfe4b5edb3097df66ddbf9639c3b3cd290734ed8.tar.gz platform-system-core-bfe4b5edb3097df66ddbf9639c3b3cd290734ed8.tar.xz platform-system-core-bfe4b5edb3097df66ddbf9639c3b3cd290734ed8.zip |
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
-rw-r--r-- | libziparchive/zip_archive.cc | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 4fe563865..7cc9ac39d 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc | |||
@@ -594,28 +594,7 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name, | |||
594 | return result; | 594 | return result; |
595 | } | 595 | } |
596 | 596 | ||
597 | // Attempts to read |len| bytes into |buf| at offset |off|. | 597 | static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, off64_t off); |
598 | // | ||
599 | // This method uses pread64 on platforms that support it and | ||
600 | // lseek64 + read on platforms that don't. This implies that | ||
601 | // callers should not rely on the |fd| offset being incremented | ||
602 | // as a side effect of this call. | ||
603 | static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, | ||
604 | off64_t off) { | ||
605 | #ifdef HAVE_PREAD | ||
606 | return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off)); | ||
607 | #else | ||
608 | // The only supported platform that doesn't support pread at the moment | ||
609 | // is Windows. Only recent versions of windows support unix like forks, | ||
610 | // and even there the semantics are quite different. | ||
611 | if (lseek64(fd, off, SEEK_SET) != off) { | ||
612 | ALOGW("Zip: failed seek to offset %" PRId64, off); | ||
613 | return kIoError; | ||
614 | } | ||
615 | |||
616 | return TEMP_FAILURE_RETRY(read(fd, buf, len)); | ||
617 | #endif // HAVE_PREAD | ||
618 | } | ||
619 | 598 | ||
620 | /* | 599 | /* |
621 | * Parses the Zip archive's Central Directory. Allocates and populates the | 600 | * Parses the Zip archive's Central Directory. Allocates and populates the |
@@ -778,6 +757,29 @@ static int32_t UpdateEntryFromDataDescriptor(int fd, | |||
778 | return 0; | 757 | return 0; |
779 | } | 758 | } |
780 | 759 | ||
760 | // Attempts to read |len| bytes into |buf| at offset |off|. | ||
761 | // | ||
762 | // This method uses pread64 on platforms that support it and | ||
763 | // lseek64 + read on platforms that don't. This implies that | ||
764 | // callers should not rely on the |fd| offset being incremented | ||
765 | // as a side effect of this call. | ||
766 | static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, | ||
767 | off64_t off) { | ||
768 | #ifdef HAVE_PREAD | ||
769 | return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off)); | ||
770 | #else | ||
771 | // The only supported platform that doesn't support pread at the moment | ||
772 | // is Windows. Only recent versions of windows support unix like forks, | ||
773 | // and even there the semantics are quite different. | ||
774 | if (lseek64(fd, off, SEEK_SET) != off) { | ||
775 | ALOGW("Zip: failed seek to offset %" PRId64, off); | ||
776 | return kIoError; | ||
777 | } | ||
778 | |||
779 | return TEMP_FAILURE_RETRY(read(fd, buf, len)); | ||
780 | #endif // HAVE_PREAD | ||
781 | } | ||
782 | |||
781 | static int32_t FindEntry(const ZipArchive* archive, const int ent, | 783 | static int32_t FindEntry(const ZipArchive* archive, const int ent, |
782 | ZipEntry* data) { | 784 | ZipEntry* data) { |
783 | const uint16_t nameLen = archive->hash_table[ent].name_length; | 785 | const uint16_t nameLen = archive->hash_table[ent].name_length; |