2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Read-only access to Zip archives, with minimal heap allocation.
20 #define LOG_TAG "zipro"
21 //#define LOG_NDEBUG 0
22 #include <utils/Log.h>
23 #include <utils/Compat.h>
24 #include <utils/ZipFileRO.h>
25 #include <utils/misc.h>
26 #include <utils/threads.h>
37 * We must open binary files using open(path, ... | O_BINARY) under Windows.
38 * Otherwise strange read errors will happen.
44 using namespace android;
49 #define kEOCDSignature 0x06054b50
51 #define kEOCDNumEntries 8 // offset to #of entries in file
52 #define kEOCDSize 12 // size of the central directory
53 #define kEOCDFileOffset 16 // offset to central directory
55 #define kMaxCommentLen 65535 // longest possible in ushort
56 #define kMaxEOCDSearch (kMaxCommentLen + kEOCDLen)
58 #define kLFHSignature 0x04034b50
59 #define kLFHLen 30 // excluding variable-len fields
60 #define kLFHNameLen 26 // offset to filename length
61 #define kLFHExtraLen 28 // offset to extra length
63 #define kCDESignature 0x02014b50
64 #define kCDELen 46 // excluding variable-len fields
65 #define kCDEMethod 10 // offset to compression method
66 #define kCDEModWhen 12 // offset to modification timestamp
67 #define kCDECRC 16 // offset to entry CRC
68 #define kCDECompLen 20 // offset to compressed length
69 #define kCDEUncompLen 24 // offset to uncompressed length
70 #define kCDENameLen 28 // offset to filename length
71 #define kCDEExtraLen 30 // offset to extra length
72 #define kCDECommentLen 32 // offset to comment length
73 #define kCDELocalOffset 42 // offset to local hdr
76 * The values we return for ZipEntryRO use 0 as an invalid value, so we
77 * want to adjust the hash table index by a fixed amount. Using a large
78 * value helps insure that people don't mix & match arguments, e.g. to
81 #define kZipEntryAdj 10000
83 ZipFileRO::~ZipFileRO() {
86 mDirectoryMap->release();
88 TEMP_FAILURE_RETRY(close(mFd));
94 * Convert a ZipEntryRO to a hash table index, verifying that it's in a
97 int ZipFileRO::entryToIndex(const ZipEntryRO entry) const
99 long ent = ((long) entry) - kZipEntryAdj;
100 if (ent < 0 || ent >= mHashTableSize || mHashTable[ent].name == NULL) {
101 ALOGW("Invalid ZipEntryRO %p (%ld)\n", entry, ent);
109 * Open the specified file read-only. We memory-map the entire thing and
110 * close the file before returning.
112 status_t ZipFileRO::open(const char* zipFileName)
116 assert(mDirectoryMap == NULL);
119 * Open and map the specified file.
121 fd = ::open(zipFileName, O_RDONLY | O_BINARY);
123 ALOGW("Unable to open zip '%s': %s\n", zipFileName, strerror(errno));
124 return NAME_NOT_FOUND;
127 mFileLength = lseek64(fd, 0, SEEK_END);
128 if (mFileLength < kEOCDLen) {
129 TEMP_FAILURE_RETRY(close(fd));
130 return UNKNOWN_ERROR;
133 if (mFileName != NULL) {
136 mFileName = strdup(zipFileName);
141 * Find the Central Directory and store its size and number of entries.
143 if (!mapCentralDirectory()) {
148 * Verify Central Directory and create data structures for fast access.
150 if (!parseZipArchive()) {
159 TEMP_FAILURE_RETRY(close(fd));
160 return UNKNOWN_ERROR;
164 * Parse the Zip archive, verifying its contents and initializing internal
167 bool ZipFileRO::mapCentralDirectory(void)
169 ssize_t readAmount = kMaxEOCDSearch;
170 if (readAmount > (ssize_t) mFileLength)
171 readAmount = mFileLength;
173 unsigned char* scanBuf = (unsigned char*) malloc(readAmount);
174 if (scanBuf == NULL) {
175 ALOGW("couldn't allocate scanBuf: %s", strerror(errno));
181 * Make sure this is a Zip archive.
183 if (lseek64(mFd, 0, SEEK_SET) != 0) {
184 ALOGW("seek to start failed: %s", strerror(errno));
189 ssize_t actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, sizeof(int32_t)));
190 if (actual != (ssize_t) sizeof(int32_t)) {
191 ALOGI("couldn't read first signature from zip archive: %s", strerror(errno));
197 unsigned int header = get4LE(scanBuf);
198 if (header == kEOCDSignature) {
199 ALOGI("Found Zip archive, but it looks empty\n");
202 } else if (header != kLFHSignature) {
203 ALOGV("Not a Zip archive (found 0x%08x)\n", header);
210 * Perform the traditional EOCD snipe hunt.
212 * We're searching for the End of Central Directory magic number,
213 * which appears at the start of the EOCD block. It's followed by
214 * 18 bytes of EOCD stuff and up to 64KB of archive comment. We
215 * need to read the last part of the file into a buffer, dig through
216 * it to find the magic number, parse some values out, and use those
217 * to determine the extent of the CD.
219 * We start by pulling in the last part of the file.
221 off64_t searchStart = mFileLength - readAmount;
223 if (lseek64(mFd, searchStart, SEEK_SET) != searchStart) {
224 ALOGW("seek %ld failed: %s\n", (long) searchStart, strerror(errno));
228 actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, readAmount));
229 if (actual != (ssize_t) readAmount) {
230 ALOGW("Zip: read " ZD ", expected " ZD ". Failed: %s\n",
231 (ZD_TYPE) actual, (ZD_TYPE) readAmount, strerror(errno));
237 * Scan backward for the EOCD magic. In an archive without a trailing
238 * comment, we'll find it on the first try. (We may want to consider
239 * doing an initial minimal read; if we don't find it, retry with a
240 * second read as above.)
243 for (i = readAmount - kEOCDLen; i >= 0; i--) {
244 if (scanBuf[i] == 0x50 && get4LE(&scanBuf[i]) == kEOCDSignature) {
245 ALOGV("+++ Found EOCD at buf+%d\n", i);
250 ALOGD("Zip: EOCD not found, %s is not zip\n", mFileName);
255 off64_t eocdOffset = searchStart + i;
256 const unsigned char* eocdPtr = scanBuf + i;
258 assert(eocdOffset < mFileLength);
261 * Grab the CD offset and size, and the number of entries in the
262 * archive. After that, we can release our EOCD hunt buffer.
264 unsigned int numEntries = get2LE(eocdPtr + kEOCDNumEntries);
265 unsigned int dirSize = get4LE(eocdPtr + kEOCDSize);
266 unsigned int dirOffset = get4LE(eocdPtr + kEOCDFileOffset);
269 // Verify that they look reasonable.
270 if ((long long) dirOffset + (long long) dirSize > (long long) eocdOffset) {
271 ALOGW("bad offsets (dir %ld, size %u, eocd %ld)\n",
272 (long) dirOffset, dirSize, (long) eocdOffset);
275 if (numEntries == 0) {
276 ALOGW("empty archive?\n");
280 ALOGV("+++ numEntries=%d dirSize=%d dirOffset=%d\n",
281 numEntries, dirSize, dirOffset);
283 mDirectoryMap = new FileMap();
284 if (mDirectoryMap == NULL) {
285 ALOGW("Unable to create directory map: %s", strerror(errno));
289 if (!mDirectoryMap->create(mFileName, mFd, dirOffset, dirSize, true)) {
290 ALOGW("Unable to map '%s' (" ZD " to " ZD "): %s\n", mFileName,
291 (ZD_TYPE) dirOffset, (ZD_TYPE) (dirOffset + dirSize), strerror(errno));
295 mNumEntries = numEntries;
296 mDirectoryOffset = dirOffset;
301 bool ZipFileRO::parseZipArchive(void)
304 const unsigned char* cdPtr = (const unsigned char*) mDirectoryMap->getDataPtr();
305 size_t cdLength = mDirectoryMap->getDataLength();
306 int numEntries = mNumEntries;
309 * Create hash table. We have a minimum 75% load factor, possibly as
310 * low as 50% after we round off to a power of 2.
312 mHashTableSize = roundUpPower2(1 + (numEntries * 4) / 3);
313 mHashTable = (HashEntry*) calloc(mHashTableSize, sizeof(HashEntry));
316 * Walk through the central directory, adding entries to the hash
319 const unsigned char* ptr = cdPtr;
320 for (int i = 0; i < numEntries; i++) {
321 if (get4LE(ptr) != kCDESignature) {
322 ALOGW("Missed a central dir sig (at %d)\n", i);
325 if (ptr + kCDELen > cdPtr + cdLength) {
326 ALOGW("Ran off the end (at %d)\n", i);
330 long localHdrOffset = (long) get4LE(ptr + kCDELocalOffset);
331 if (localHdrOffset >= mDirectoryOffset) {
332 ALOGW("bad LFH offset %ld at entry %d\n", localHdrOffset, i);
336 unsigned int fileNameLen, extraLen, commentLen, hash;
338 fileNameLen = get2LE(ptr + kCDENameLen);
339 extraLen = get2LE(ptr + kCDEExtraLen);
340 commentLen = get2LE(ptr + kCDECommentLen);
342 /* add the CDE filename to the hash table */
343 hash = computeHash((const char*)ptr + kCDELen, fileNameLen);
344 addToHash((const char*)ptr + kCDELen, fileNameLen, hash);
346 ptr += kCDELen + fileNameLen + extraLen + commentLen;
347 if ((size_t)(ptr - cdPtr) > cdLength) {
348 ALOGW("bad CD advance (%d vs " ZD ") at entry %d\n",
349 (int) (ptr - cdPtr), (ZD_TYPE) cdLength, i);
353 ALOGV("+++ zip good scan %d entries\n", numEntries);
361 * Simple string hash function for non-null-terminated strings.
363 /*static*/ unsigned int ZipFileRO::computeHash(const char* str, int len)
365 unsigned int hash = 0;
368 hash = hash * 31 + *str++;
374 * Add a new entry to the hash table.
376 void ZipFileRO::addToHash(const char* str, int strLen, unsigned int hash)
378 int ent = hash & (mHashTableSize-1);
381 * We over-allocate the table, so we're guaranteed to find an empty slot.
383 while (mHashTable[ent].name != NULL)
384 ent = (ent + 1) & (mHashTableSize-1);
386 mHashTable[ent].name = str;
387 mHashTable[ent].nameLen = strLen;
391 * Find a matching entry.
393 * Returns NULL if not found.
395 ZipEntryRO ZipFileRO::findEntryByName(const char* fileName) const
398 * If the ZipFileRO instance is not initialized, the entry number will
399 * end up being garbage since mHashTableSize is -1.
401 if (mHashTableSize <= 0) {
405 int nameLen = strlen(fileName);
406 unsigned int hash = computeHash(fileName, nameLen);
407 int ent = hash & (mHashTableSize-1);
409 while (mHashTable[ent].name != NULL) {
410 if (mHashTable[ent].nameLen == nameLen &&
411 memcmp(mHashTable[ent].name, fileName, nameLen) == 0)
414 return (ZipEntryRO)(long)(ent + kZipEntryAdj);
417 ent = (ent + 1) & (mHashTableSize-1);
424 * Find the Nth entry.
426 * This currently involves walking through the sparse hash table, counting
427 * non-empty entries. If we need to speed this up we can either allocate
428 * a parallel lookup table or (perhaps better) provide an iterator interface.
430 ZipEntryRO ZipFileRO::findEntryByIndex(int idx) const
432 if (idx < 0 || idx >= mNumEntries) {
433 ALOGW("Invalid index %d\n", idx);
437 for (int ent = 0; ent < mHashTableSize; ent++) {
438 if (mHashTable[ent].name != NULL) {
440 return (ZipEntryRO) (ent + kZipEntryAdj);
448 * Get the useful fields from the zip entry.
450 * Returns "false" if the offsets to the fields or the contents of the fields
451 * appear to be bogus.
453 bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
454 size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32) const
458 const int ent = entryToIndex(entry);
462 HashEntry hashEntry = mHashTable[ent];
465 * Recover the start of the central directory entry from the filename
466 * pointer. The filename is the first entry past the fixed-size data,
467 * so we can just subtract back from that.
469 const unsigned char* ptr = (const unsigned char*) hashEntry.name;
470 off64_t cdOffset = mDirectoryOffset;
474 int method = get2LE(ptr + kCDEMethod);
478 if (pModWhen != NULL)
479 *pModWhen = get4LE(ptr + kCDEModWhen);
481 *pCrc32 = get4LE(ptr + kCDECRC);
483 size_t compLen = get4LE(ptr + kCDECompLen);
484 if (pCompLen != NULL)
486 size_t uncompLen = get4LE(ptr + kCDEUncompLen);
487 if (pUncompLen != NULL)
488 *pUncompLen = uncompLen;
491 * If requested, determine the offset of the start of the data. All we
492 * have is the offset to the Local File Header, which is variable size,
493 * so we have to read the contents of the struct to figure out where
494 * the actual data starts.
496 * We also need to make sure that the lengths are not so large that
497 * somebody trying to map the compressed or uncompressed data runs
498 * off the end of the mapped region.
500 * Note we don't verify compLen/uncompLen if they don't request the
501 * dataOffset, because dataOffset is expensive to determine. However,
502 * if they don't have the file offset, they're not likely to be doing
503 * anything with the contents.
505 if (pOffset != NULL) {
506 long localHdrOffset = get4LE(ptr + kCDELocalOffset);
507 if (localHdrOffset + kLFHLen >= cdOffset) {
508 ALOGE("ERROR: bad local hdr offset in zip\n");
512 unsigned char lfhBuf[kLFHLen];
516 * This file descriptor might be from zygote's preloaded assets,
517 * so we need to do an pread64() instead of a lseek64() + read() to
518 * guarantee atomicity across the processes with the shared file
522 TEMP_FAILURE_RETRY(pread64(mFd, lfhBuf, sizeof(lfhBuf), localHdrOffset));
524 if (actual != sizeof(lfhBuf)) {
525 ALOGW("failed reading lfh from offset %ld\n", localHdrOffset);
529 if (get4LE(lfhBuf) != kLFHSignature) {
530 ALOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
531 "got: data=0x%08lx\n",
532 localHdrOffset, kLFHSignature, get4LE(lfhBuf));
535 #else /* HAVE_PREAD */
537 * For hosts don't have pread64() we cannot guarantee atomic reads from
538 * an offset in a file. Android should never run on those platforms.
539 * File descriptors inherited from a fork() share file offsets and
540 * there would be nothing to protect from two different processes
541 * calling lseek64() concurrently.
545 AutoMutex _l(mFdLock);
547 if (lseek64(mFd, localHdrOffset, SEEK_SET) != localHdrOffset) {
548 ALOGW("failed seeking to lfh at offset %ld\n", localHdrOffset);
553 TEMP_FAILURE_RETRY(read(mFd, lfhBuf, sizeof(lfhBuf)));
554 if (actual != sizeof(lfhBuf)) {
555 ALOGW("failed reading lfh from offset %ld\n", localHdrOffset);
559 if (get4LE(lfhBuf) != kLFHSignature) {
560 off64_t actualOffset = lseek64(mFd, 0, SEEK_CUR);
561 ALOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
562 "got: offset=" ZD " data=0x%08lx\n",
563 localHdrOffset, kLFHSignature, (ZD_TYPE) actualOffset, get4LE(lfhBuf));
567 #endif /* HAVE_PREAD */
569 off64_t dataOffset = localHdrOffset + kLFHLen
570 + get2LE(lfhBuf + kLFHNameLen) + get2LE(lfhBuf + kLFHExtraLen);
571 if (dataOffset >= cdOffset) {
572 ALOGW("bad data offset %ld in zip\n", (long) dataOffset);
577 if ((off64_t)(dataOffset + compLen) > cdOffset) {
578 ALOGW("bad compressed length in zip (%ld + " ZD " > %ld)\n",
579 (long) dataOffset, (ZD_TYPE) compLen, (long) cdOffset);
583 if (method == kCompressStored &&
584 (off64_t)(dataOffset + uncompLen) > cdOffset)
586 ALOGE("ERROR: bad uncompressed length in zip (%ld + " ZD " > %ld)\n",
587 (long) dataOffset, (ZD_TYPE) uncompLen, (long) cdOffset);
591 *pOffset = dataOffset;
598 * Copy the entry's filename to the buffer.
600 int ZipFileRO::getEntryFileName(ZipEntryRO entry, char* buffer, int bufLen)
603 int ent = entryToIndex(entry);
607 int nameLen = mHashTable[ent].nameLen;
608 if (bufLen < nameLen+1)
611 memcpy(buffer, mHashTable[ent].name, nameLen);
612 buffer[nameLen] = '\0';
617 * Create a new FileMap object that spans the data in "entry".
619 FileMap* ZipFileRO::createEntryFileMap(ZipEntryRO entry) const
622 * TODO: the efficient way to do this is to modify FileMap to allow
623 * sub-regions of a file to be mapped. A reference-counting scheme
624 * can manage the base memory mapping. For now, we just create a brand
625 * new mapping off of the Zip archive file descriptor.
632 if (!getEntryInfo(entry, NULL, NULL, &compLen, &offset, NULL, NULL))
635 newMap = new FileMap();
636 if (!newMap->create(mFileName, mFd, offset, compLen, true)) {
645 * Uncompress an entry, in its entirety, into the provided output buffer.
647 * This doesn't verify the data's CRC, which might be useful for
648 * uncompressed data. The caller should be able to manage it.
650 bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const
652 const size_t kSequentialMin = 32768;
654 int ent = entryToIndex(entry);
659 size_t uncompLen, compLen;
661 const unsigned char* ptr;
663 getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL);
665 FileMap* file = createEntryFileMap(entry);
670 ptr = (const unsigned char*) file->getDataPtr();
673 * Experiment with madvise hint. When we want to uncompress a file,
674 * we pull some stuff out of the central dir entry and then hit a
675 * bunch of compressed or uncompressed data sequentially. The CDE
676 * visit will cause a limited amount of read-ahead because it's at
677 * the end of the file. We could end up doing lots of extra disk
678 * access if the file we're prying open is small. Bottom line is we
679 * probably don't want to turn MADV_SEQUENTIAL on and leave it on.
681 * So, if the compressed size of the file is above a certain minimum
682 * size, temporarily boost the read-ahead in the hope that the extra
683 * pair of system calls are negated by a reduction in page faults.
685 if (compLen > kSequentialMin)
686 file->advise(FileMap::SEQUENTIAL);
688 if (method == kCompressStored) {
689 memcpy(buffer, ptr, uncompLen);
691 if (!inflateBuffer(buffer, ptr, uncompLen, compLen))
695 if (compLen > kSequentialMin)
696 file->advise(FileMap::NORMAL);
707 * Uncompress an entry, in its entirety, to an open file descriptor.
709 * This doesn't verify the data's CRC, but probably should.
711 bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const
714 int ent = entryToIndex(entry);
719 size_t uncompLen, compLen;
721 const unsigned char* ptr;
723 getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL);
725 FileMap* file = createEntryFileMap(entry);
730 ptr = (const unsigned char*) file->getDataPtr();
732 if (method == kCompressStored) {
733 ssize_t actual = write(fd, ptr, uncompLen);
735 ALOGE("Write failed: %s\n", strerror(errno));
737 } else if ((size_t) actual != uncompLen) {
738 ALOGE("Partial write during uncompress (" ZD " of " ZD ")\n",
739 (ZD_TYPE) actual, (ZD_TYPE) uncompLen);
742 ALOGI("+++ successful write\n");
745 if (!inflateBuffer(fd, ptr, uncompLen, compLen))
758 * Uncompress "deflate" data from one buffer to another.
760 /*static*/ bool ZipFileRO::inflateBuffer(void* outBuf, const void* inBuf,
761 size_t uncompLen, size_t compLen)
768 * Initialize the zlib stream struct.
770 memset(&zstream, 0, sizeof(zstream));
771 zstream.zalloc = Z_NULL;
772 zstream.zfree = Z_NULL;
773 zstream.opaque = Z_NULL;
774 zstream.next_in = (Bytef*)inBuf;
775 zstream.avail_in = compLen;
776 zstream.next_out = (Bytef*) outBuf;
777 zstream.avail_out = uncompLen;
778 zstream.data_type = Z_UNKNOWN;
781 * Use the undocumented "negative window bits" feature to tell zlib
782 * that there's no zlib header waiting for it.
784 zerr = inflateInit2(&zstream, -MAX_WBITS);
786 if (zerr == Z_VERSION_ERROR) {
787 ALOGE("Installed zlib is not compatible with linked version (%s)\n",
790 ALOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
798 zerr = inflate(&zstream, Z_FINISH);
799 if (zerr != Z_STREAM_END) {
800 ALOGW("Zip inflate failed, zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)\n",
801 zerr, zstream.next_in, zstream.avail_in,
802 zstream.next_out, zstream.avail_out);
807 if (zstream.total_out != uncompLen) {
808 ALOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
809 zstream.total_out, (ZD_TYPE) uncompLen);
816 inflateEnd(&zstream); /* free up any allocated structures */
823 * Uncompress "deflate" data from one buffer to an open file descriptor.
825 /*static*/ bool ZipFileRO::inflateBuffer(int fd, const void* inBuf,
826 size_t uncompLen, size_t compLen)
829 const size_t kWriteBufSize = 32768;
830 unsigned char writeBuf[kWriteBufSize];
835 * Initialize the zlib stream struct.
837 memset(&zstream, 0, sizeof(zstream));
838 zstream.zalloc = Z_NULL;
839 zstream.zfree = Z_NULL;
840 zstream.opaque = Z_NULL;
841 zstream.next_in = (Bytef*)inBuf;
842 zstream.avail_in = compLen;
843 zstream.next_out = (Bytef*) writeBuf;
844 zstream.avail_out = sizeof(writeBuf);
845 zstream.data_type = Z_UNKNOWN;
848 * Use the undocumented "negative window bits" feature to tell zlib
849 * that there's no zlib header waiting for it.
851 zerr = inflateInit2(&zstream, -MAX_WBITS);
853 if (zerr == Z_VERSION_ERROR) {
854 ALOGE("Installed zlib is not compatible with linked version (%s)\n",
857 ALOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
863 * Loop while we have more to do.
869 zerr = inflate(&zstream, Z_NO_FLUSH);
870 if (zerr != Z_OK && zerr != Z_STREAM_END) {
871 ALOGW("zlib inflate: zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)\n",
872 zerr, zstream.next_in, zstream.avail_in,
873 zstream.next_out, zstream.avail_out);
877 /* write when we're full or when we're done */
878 if (zstream.avail_out == 0 ||
879 (zerr == Z_STREAM_END && zstream.avail_out != sizeof(writeBuf)))
881 long writeSize = zstream.next_out - writeBuf;
882 int cc = write(fd, writeBuf, writeSize);
883 if (cc != (int) writeSize) {
884 ALOGW("write failed in inflate (%d vs %ld)\n", cc, writeSize);
888 zstream.next_out = writeBuf;
889 zstream.avail_out = sizeof(writeBuf);
891 } while (zerr == Z_OK);
893 assert(zerr == Z_STREAM_END); /* other errors should've been caught */
896 if (zstream.total_out != uncompLen) {
897 ALOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
898 zstream.total_out, (ZD_TYPE) uncompLen);
905 inflateEnd(&zstream); /* free up any allocated structures */