From db21f09a8e02bcfd3fefea68084667688268f1fa Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 16 Nov 2020 23:08:18 +0000 Subject: Revert^2 "libandroidfw hardening for IncFs" 55ef6167a2c235bd88c7216238b2001b46795b79 Change-Id: I02d4890d181655dfd0a14c188468db512559d27b --- libs/androidfw/ZipFileRO.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libs/androidfw/ZipFileRO.cpp') diff --git a/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp index e77ac3df474c..52e7a70521a1 100644 --- a/libs/androidfw/ZipFileRO.cpp +++ b/libs/androidfw/ZipFileRO.cpp @@ -232,6 +232,29 @@ FileMap* ZipFileRO::createEntryFileMap(ZipEntryRO entry) const return newMap; } +/* + * Create a new incfs::IncFsFileMap object that spans the data in "entry". + */ +std::optional ZipFileRO::createEntryIncFsFileMap(ZipEntryRO entry) const +{ + const _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry); + const ZipEntry& ze = zipEntry->entry; + int fd = GetFileDescriptor(mHandle); + size_t actualLen = 0; + + if (ze.method == kCompressStored) { + actualLen = ze.uncompressed_length; + } else { + actualLen = ze.compressed_length; + } + + incfs::IncFsFileMap newMap; + if (!newMap.Create(fd, ze.offset, actualLen, mFileName)) { + return std::nullopt; + } + return std::move(newMap); +} + /* * Uncompress an entry, in its entirety, into the provided output buffer. * -- cgit v1.2.3