handle short writes when unzipping files

minzip fails if write() doesn't write all the data in one call.
Apparently this was good enough before, but it causes OTAs to fail all
the time now (maybe due to the recently-submitted kernel)?  Change
code to attempt continuing after short writes.
This commit is contained in:
Doug Zongker
2009-04-29 16:52:04 -07:00
parent f554ceb050
commit 596271fa71
+21 -5
View File
@@ -772,13 +772,29 @@ bool mzReadZipEntry(const ZipArchive* pArchive, const ZipEntry* pEntry,
static bool writeProcessFunction(const unsigned char *data, int dataLen, static bool writeProcessFunction(const unsigned char *data, int dataLen,
void *fd) void *fd)
{ {
ssize_t n = write((int)fd, data, dataLen); int zeroWrites = 0;
if (n != dataLen) { ssize_t soFar = 0;
LOGE("Can't write %d bytes (only %ld) from zip file: %s\n", do {
dataLen, n, strerror(errno)); ssize_t n = write((int)fd, data+soFar, dataLen-soFar);
if (n < 0) {
LOGE("Error writing %ld bytes from zip file: %s\n",
dataLen-soFar, strerror(errno));
return false;
} else if (n > 0) {
soFar += n;
if (soFar == dataLen) return true;
if (soFar > dataLen) {
LOGE("write overrun? (%ld bytes instead of %d)\n",
soFar, dataLen);
return false; return false;
} }
return true; zeroWrites = 0;
} else {
++zeroWrites;
}
} while (zeroWrites < 5);
LOGE("too many consecutive zero-length writes\n");
return false;
} }
/* /*