You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/08/04 22:00:29 UTC

incubator-corinthia git commit: ready for integration

Repository: incubator-corinthia
Updated Branches:
  refs/heads/newZipExperiment2 7dea936f3 -> 1cd9d9f68


ready for integration


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/1cd9d9f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/1cd9d9f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/1cd9d9f6

Branch: refs/heads/newZipExperiment2
Commit: 1cd9d9f688f58cd6b7e83846d09d5d1ec142d2c2
Parents: 7dea936
Author: jani <ja...@apache.org>
Authored: Tue Aug 4 22:00:12 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Tue Aug 4 22:00:12 2015 +0200

----------------------------------------------------------------------
 DocFormats/platform/src/Wrapper_zip.c | 70 +++++++++++-------------------
 1 file changed, 25 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/1cd9d9f6/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 18b6e64..b9f3bc5 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -122,52 +122,34 @@ static int readDirectory(FILE *zipFile, DFextZipHandleP zipHandle)
 	// Each file has a global and a local entry, read both in a loop
 
 
+	// Find firs directory entry
+	if (fseek(zipFile, zipOffset, SEEK_SET))
+		return -1;
+
 	// loop through all entries
 	for (i = 0; i < zipHandle->zipFileCount; i++) {
-		ZipDirectoryRecord *recDir = (ZipDirectoryRecord *)workBuf;
+		ZipDirectoryRecord *recDir   = (ZipDirectoryRecord *)workBuf;
+		DFextZipDirEntry   *dirEntry = &zipHandle->zipFileEntries[i];
 
 		// Find next directory entry, read it and verify signature
- 		if (fseek(zipFile, zipOffset, SEEK_SET)
-		    || fread(workBuf, 1, sizeof(ZipDirectoryRecord), zipFile) < sizeof(ZipDirectoryRecord)
+ 		if (fread(workBuf, 1, sizeof(ZipDirectoryRecord), zipFile) < sizeof(ZipDirectoryRecord)
 			|| recDir->signature != ZipDirectoryRecord_signature)
-				return -1;
+			return -1;
 
 		// Skip extra info and store pointer at next entry
-		if (fseek(zipFile, recDir->extraFieldLength, SEEK_CUR)
-			|| fseek(zipFile, recDir->fileCommentLength, SEEK_CUR)
-			|| fseek(zipFile, recDir->fileNameLength, SEEK_CUR))
+		if (fseek(zipFile, recDir->extraFieldLength + recDir->fileCommentLength, SEEK_CUR))
 			return -1;
-		zipOffset = ftell(zipFile);
-
-
-		//***** Read File header *****
-		// Each file starts with a local header
-		{
-			ZipFileHeader    *recFile     = (ZipFileHeader *)workBuf;
-			DFextZipDirEntry *zipDirEntry = &zipHandle->zipFileEntries[i];
-
-			// find local file info, read it and verify signature
-			if (fseek(zipFile, recDir->relativeOffsetOflocalHeader, SEEK_SET)
-				|| fread(workBuf, 1, sizeof(ZipFileHeader), zipFile) < sizeof(ZipFileHeader)
-				|| recFile->signature != ZipFileHeader_signature)
-				return -1;
-
-			// Save information
-			zipDirEntry->compressedSize    = recFile->compressedSize;
-			zipDirEntry->uncompressedSize  = recFile->uncompressedSize;
-			zipDirEntry->compressionMethod = recFile->compressionMethod;
-
-			// Add filename
-			zipDirEntry->fileName = xmalloc(recFile->fileNameLength + 1);
-			if (fread(zipDirEntry->fileName, 1, recFile->fileNameLength, zipFile) < (unsigned long)recFile->fileNameLength)
-				return -1;
-			zipDirEntry->fileName[recFile->fileNameLength] = '\0';
-
-			// skip extra field
-			if (fseek(zipFile, recFile->extraFieldLength, SEEK_CUR))
-				return -1;
-			zipDirEntry->offset = ftell(zipFile);
-		}
+
+		dirEntry->compressedSize    = recDir->compressedSize;
+		dirEntry->uncompressedSize  = recDir->uncompressedSize;
+		dirEntry->compressionMethod = recDir->compressionMethod;
+		dirEntry->offset            = recDir->relativeOffsetOflocalHeader;
+
+		// Add filename
+		dirEntry->fileName = xmalloc(recDir->fileNameLength + 1);
+		if (fread(dirEntry->fileName, 1, recDir->fileNameLength, zipFile) < (unsigned long)recDir->fileNameLength)
+			return -1;
+		dirEntry->fileName[recDir->fileNameLength] = '\0';
 	};
 
 	return 0;
@@ -250,11 +232,15 @@ DFextZipHandleP DFextZipOpen(const char *zipFilename) {
 
 unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zipEntry) {
 	unsigned char *fileBuf = xmalloc(zipEntry->uncompressedSize);
+    ZipFileHeader  recFile;
 	z_stream       strm;
 
 
 	// Position in front of file
-	if (fseek(zipHandle->zipFile, zipEntry->offset, SEEK_SET)) {
+	if (fseek(zipHandle->zipFile, zipEntry->offset, SEEK_SET)
+		|| fread(&recFile, 1, sizeof(ZipFileHeader), zipHandle->zipFile) < sizeof(ZipFileHeader)
+		|| recFile.signature != ZipFileHeader_signature
+		|| fseek(zipHandle->zipFile, recFile.extraFieldLength + recFile.fileNameLength, SEEK_CUR)) {
 		free(fileBuf);
 		return NULL;
 	}
@@ -269,12 +255,6 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
 		return fileBuf;
 	}
 
-	// we only handle the zlib method
-	if (zipEntry->compressionMethod != Z_DEFLATED) {
-		free(fileBuf);
-		return NULL;
-	}
-
 
 	//***** Handle zlib inflate *****