diff options
| author | 2010-09-24 11:33:29 -0700 | |
|---|---|---|
| committer | 2010-09-24 11:33:29 -0700 | |
| commit | 7f3a7afc92214b5bfc82e7301f812b0147aa7cbc (patch) | |
| tree | 97923b5de3cb20d774f712654d8655c89b27d06b | |
| parent | d3eaa1524615d5b0f369c160b36f0a66cc664be0 (diff) | |
| parent | fa98920b7192d0db8d22d9345b750810f89f9cdd (diff) | |
Merge "Add locking around ZIP seeking" into gingerbread
| -rw-r--r-- | include/utils/ZipFileRO.h | 8 | ||||
| -rw-r--r-- | libs/utils/ZipFileRO.cpp | 27 |
2 files changed, 23 insertions, 12 deletions
diff --git a/include/utils/ZipFileRO.h b/include/utils/ZipFileRO.h index 97d31f4db4..9668bdeef5 100644 --- a/include/utils/ZipFileRO.h +++ b/include/utils/ZipFileRO.h @@ -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; diff --git a/libs/utils/ZipFileRO.cpp b/libs/utils/ZipFileRO.cpp index 2d53136c14..59809c2f94 100644 --- a/libs/utils/ZipFileRO.cpp +++ b/libs/utils/ZipFileRO.cpp @@ -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,15 +497,21 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen, } unsigned char lfhBuf[kLFHLen]; - 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; + + { + 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) { |