summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-09-24 07:57:37 -0700
committerAlex Ray <aray@google.com>2013-07-30 13:56:55 -0700
commitf7c1be0e62dea8a3f8b2d9b97689de964484f4db (patch)
tree821179728ff1aa1d5272318af659f2f52ff9bbdf /libs
parentd18051870e8e2a5f55237a2c11fde75f46082639 (diff)
downloadsystem_core-f7c1be0e62dea8a3f8b2d9b97689de964484f4db.zip
system_core-f7c1be0e62dea8a3f8b2d9b97689de964484f4db.tar.gz
system_core-f7c1be0e62dea8a3f8b2d9b97689de964484f4db.tar.bz2
Add locking around ZIP seeking
Since we switched to seeking to the LFH to verify its existence instead of a huge mmap of the file, we have to guarantee that another seek doesn't happen before we finish our read on the LFH. Change-Id: If8135d9cb6f2f5cc4db734eafa4f6b5f6269c62a
Diffstat (limited to 'libs')
-rw-r--r--libs/utils/ZipFileRO.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/libs/utils/ZipFileRO.cpp b/libs/utils/ZipFileRO.cpp
index 2d53136..59809c2 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) {