From 4600dd053dbdbd4b95f3b11057a1cc55b99f9c77 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Tue, 16 Jun 2015 12:02:57 +0100 Subject: ZipFileRO: Use precise widths for zip file types. getEntryInfo crashes on 64-bit devices because "long" types were being passed int pointers (that pointed to a stack frame) that were reinterpret_cast'ed to long* (sigh.). To fix this issue once and for all, use types with explicitly defined widths. This change also removes some dead invariant checking from Asset.cpp instead of cleaning it up. Note that we've introduced a wart in NativeLibraryHelper, where we need to deal with zlib's uLong type, which is "at least 32 bits wide". bug: 21622286 Change-Id: Iae675a9601db7aae03a8b80b40321d2cc1d97f50 --- include/androidfw/Asset.h | 7 +++---- include/androidfw/ZipFileRO.h | 16 +++++++++------- include/androidfw/ZipUtils.h | 5 +++-- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/androidfw/Asset.h b/include/androidfw/Asset.h index 1fe0e06..ee77e97 100644 --- a/include/androidfw/Asset.h +++ b/include/androidfw/Asset.h @@ -182,11 +182,11 @@ private: /* * Create the asset from a memory-mapped file segment with compressed - * data. "method" is a Zip archive compression method constant. + * data. * * The asset takes ownership of the FileMap. */ - static Asset* createFromCompressedMap(FileMap* dataMap, int method, + static Asset* createFromCompressedMap(FileMap* dataMap, size_t uncompressedLen, AccessMode mode); @@ -286,8 +286,7 @@ public: * * On success, the object takes ownership of "fd". */ - status_t openChunk(FileMap* dataMap, int compressionMethod, - size_t uncompressedLen); + status_t openChunk(FileMap* dataMap, size_t uncompressedLen); /* * Standard Asset interfaces. diff --git a/include/androidfw/ZipFileRO.h b/include/androidfw/ZipFileRO.h index ad5be12..1410d87 100644 --- a/include/androidfw/ZipFileRO.h +++ b/include/androidfw/ZipFileRO.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -68,9 +69,9 @@ typedef void* ZipEntryRO; class ZipFileRO { public: /* Zip compression methods we support */ - enum { - kCompressStored = 0, // no compression - kCompressDeflated = 8, // standard deflate + enum : uint16_t { + kCompressStored = 0, + kCompressDeflated = 8 }; /* @@ -108,10 +109,10 @@ public: /* * Copy the filename into the supplied buffer. Returns 0 on success, - * -1 if "entry" is invalid, or the filename length if it didn't fit. The + * -1 if "entry" is invalid, or the filename length if it didn't fit. The * length, and the returned string, include the null-termination. */ - int getEntryFileName(ZipEntryRO entry, char* buffer, int bufLen) const; + int getEntryFileName(ZipEntryRO entry, char* buffer, size_t bufLen) const; /* * Get the vital stats for an entry. Pass in NULL pointers for anything @@ -122,8 +123,9 @@ public: * Returns "false" if "entry" is bogus or if the data in the Zip file * appears to be bad. */ - bool getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen, - size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32) const; + bool getEntryInfo(ZipEntryRO entry, uint16_t* pMethod, uint32_t* pUncompLen, + uint32_t* pCompLen, off64_t* pOffset, uint32_t* pModWhen, + uint32_t* pCrc32) const; /* * Create a new FileMap object that maps a subset of the archive. For diff --git a/include/androidfw/ZipUtils.h b/include/androidfw/ZipUtils.h index 6bea25a..094eaa8 100644 --- a/include/androidfw/ZipUtils.h +++ b/include/androidfw/ZipUtils.h @@ -20,6 +20,7 @@ #ifndef __LIBS_ZIPUTILS_H #define __LIBS_ZIPUTILS_H +#include #include #include @@ -63,8 +64,8 @@ public: /* * Utility function to convert ZIP's time format to a timespec struct. */ - static inline void zipTimeToTimespec(long when, struct tm* timespec) { - const long date = when >> 16; + static inline void zipTimeToTimespec(uint32_t when, struct tm* timespec) { + const uint32_t date = when >> 16; timespec->tm_year = ((date >> 9) & 0x7F) + 80; // Zip is years since 1980 timespec->tm_mon = (date >> 5) & 0x0F; timespec->tm_mday = date & 0x1F; -- cgit v1.1