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

Commit d6d93dbb authored by Kenny Root's avatar Kenny Root Committed by Android Git Automerger
Browse files

am 3e07c000: am 74865ef6: Merge "Add locking around ZIP seeking" into gingerbread

Merge commit '3e07c0007b10fbda945516acaf6b2a8787a6ca06'

* commit '3e07c0007b10fbda945516acaf6b2a8787a6ca06':
  Add locking around ZIP seeking
parents 68a63161 03944f29
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -24,8 +24,9 @@
#ifndef __LIBS_ZIPFILERO_H
#define __LIBS_ZIPFILERO_H

#include "Errors.h"
#include "FileMap.h"
#include <utils/Errors.h>
#include <utils/FileMap.h>
#include <utils/threads.h>

#include <stdio.h>
#include <stdlib.h>
@@ -211,6 +212,9 @@ private:
    /* open Zip archive */
    int         mFd;

    /* Lock for handling the file descriptor (seeks, etc) */
    mutable Mutex mFdLock;

    /* zip file name */
    char*       mFileName;

+17 −10
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/ZipFileRO.h>
#include <utils/Log.h>
#include <utils/misc.h>
#include <utils/threads.h>

#include <zlib.h>

@@ -195,7 +196,7 @@ bool ZipFileRO::mapCentralDirectory(void)
            free(scanBuf);
            return false;
        } else if (header != kLFHSignature) {
            LOGV("Not a Zip archive (found 0x%08x)\n", val);
            LOGV("Not a Zip archive (found 0x%08x)\n", header);
            free(scanBuf);
            return false;
        }
@@ -496,16 +497,22 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
        }

        unsigned char lfhBuf[kLFHLen];

        {
            AutoMutex _l(mFdLock);

            if (lseek(mFd, localHdrOffset, SEEK_SET) != localHdrOffset) {
                LOGW("failed seeking to lfh at offset %ld\n", localHdrOffset);
                return false;
            }

            ssize_t actual =
                TEMP_FAILURE_RETRY(read(mFd, lfhBuf, sizeof(lfhBuf)));
            if (actual != sizeof(lfhBuf)) {
                LOGW("failed reading lfh from offset %ld\n", localHdrOffset);
                return false;
            }
        }

        if (get4LE(lfhBuf) != kLFHSignature) {
            LOGW("didn't find signature at start of lfh, offset=%ld (got 0x%08lx, expected 0x%08x)\n",