Return-Path: X-Original-To: apmail-corinthia-commits-archive@minotaur.apache.org Delivered-To: apmail-corinthia-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1DE191865A for ; Thu, 30 Jul 2015 19:38:29 +0000 (UTC) Received: (qmail 33552 invoked by uid 500); 30 Jul 2015 19:38:07 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 33532 invoked by uid 500); 30 Jul 2015 19:38:07 -0000 Mailing-List: contact commits-help@corinthia.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@corinthia.incubator.apache.org Delivered-To: mailing list commits@corinthia.incubator.apache.org Received: (qmail 33523 invoked by uid 99); 30 Jul 2015 19:38:07 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jul 2015 19:38:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 88DC2C4F95 for ; Thu, 30 Jul 2015 19:38:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.77 X-Spam-Level: * X-Spam-Status: No, score=1.77 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id GwPdYNGgJrHz for ; Thu, 30 Jul 2015 19:38:05 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id CB1F543DE9 for ; Thu, 30 Jul 2015 19:38:04 +0000 (UTC) Received: (qmail 33478 invoked by uid 99); 30 Jul 2015 19:38:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jul 2015 19:38:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 42CA1E7136; Thu, 30 Jul 2015 19:38:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jani@apache.org To: commits@corinthia.incubator.apache.org Date: Thu, 30 Jul 2015 19:38:04 -0000 Message-Id: <2c1327b91ac74c33b90d171f9d7ef794@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] incubator-corinthia git commit: work Repository: incubator-corinthia Updated Branches: refs/heads/newZipExperiment 1257d3f94 -> 055b257ca work Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/5f67db93 Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/5f67db93 Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/5f67db93 Branch: refs/heads/newZipExperiment Commit: 5f67db937dbc4d131cc7e2b15e722614e629ead3 Parents: 1257d3f Author: jani Authored: Thu Jul 30 20:21:53 2015 +0200 Committer: jani Committed: Thu Jul 30 20:21:53 2015 +0200 ---------------------------------------------------------------------- DocFormats/headers/DFPlatform.h | 2 +- DocFormats/platform/src/Wrapper_zip.c | 68 ++++++++++++++++----------- DocFormats/platform/tests/WrapperTests.c | 8 ++-- 3 files changed, 47 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5f67db93/DocFormats/headers/DFPlatform.h ---------------------------------------------------------------------- diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h index f55ccc2..cd947b1 100644 --- a/DocFormats/headers/DFPlatform.h +++ b/DocFormats/headers/DFPlatform.h @@ -70,7 +70,7 @@ void DFInitOnce(DFOnce *once, DFOnceFunction fun); // Zip functions typedef struct { - FILE *zip; + FILE *zipFile; } DFextZipHandle; typedef DFextZipHandle * DFextZipHandleP; http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5f67db93/DocFormats/platform/src/Wrapper_zip.c ---------------------------------------------------------------------- diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c index e73234c..d61f865 100644 --- a/DocFormats/platform/src/Wrapper_zip.c +++ b/DocFormats/platform/src/Wrapper_zip.c @@ -17,47 +17,61 @@ #include #include #include +#include #include "DFPlatform.h" #include "zlib.h" +#pragma pack(1) +typedef struct { + uint32_t signature; // 0x06054b50 + uint16_t diskNumber; // NOT USED + uint16_t centralDirectoryDiskNumber; // NOT USED + uint16_t numEntriesThisDisk; // NOT USED + uint16_t numEntries; // Number of files in Zip + uint32_t centralDirectorySize; // Size of directory (we only have one) + uint32_t centralDirectoryOffset; // Offset of directory in file (fseek) + uint16_t zipCommentLength; // NOT USED + // Followed by .ZIP file comment (variable size) +} ZipEndRecord; +#pragma pack() +#define WORK_BUF_SIZE 65535 + + +static int readEndRecord(FILE *zipFile, DFextZipHandleP zipHandle) +{ + long fileSize, readBytes, i; + unsigned char workBuf[WORK_BUF_SIZE]; + + // find end of file, and calculate size + if (fseek(zipFile, 0, SEEK_END)) + return -1; + fileSize = ftell(zipFile); + if ( fileSize <= sizeof(ZipEndRecord) ) { + return -1; + + // Read WORK_BUF_SIZE of filesize from end of file to locate EndRecord + readBytes = (fileSize < sizeof(workBuf)) ? fileSize : sizeof(workBuf); + if (fseek(zipFile, fileSize - readBytes, SEEK_SET)) + return -1; + if (fread(workBuf, 1, readBytes, zipFile) < readBytes) + return -1; +} + DFextZipHandleP DFextZipOpen(const char *zipFilename) { DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle)); // open zip file for reading - zipHandle->zip = fopen(zipFilename, "rb"); - if (!zipHandle->zip) { - free(zipHandle); - return NULL; + zipHandle->zipFile = fopen(zipFilename, "rb"); + if (zipHandle->zipFile && + readEndRecord(zipHandle->zipFile, zipHandle)) { + return zipHandle; } - int jzReadEndRecord(FILE *zip, JZEndRecord *endRecord) { - long fileSize, readBytes, i; - JZEndRecord *er; - - if (fseek(zip, 0, SEEK_END)) { - fprintf(stderr, "Couldn't go to end of zip file!"); - return Z_ERRNO; - } - - if ((fileSize = ftell(zip)) <= sizeof(JZEndRecord)) { - fprintf(stderr, "Too small file to be a zip!"); - return Z_ERRNO; - } - - readBytes = (fileSize < sizeof(jzBuffer)) ? fileSize : sizeof(jzBuffer); - if (fseek(zip, fileSize - readBytes, SEEK_SET)) { - fprintf(stderr, "Cannot seek in zip file!"); - return Z_ERRNO; - } - if (fread(jzBuffer, 1, readBytes, zip) < readBytes) { - fprintf(stderr, "Couldn't read end of zip file!"); - return Z_ERRNO; - } // Naively assume signature can only be found in one place... for (i = readBytes - sizeof(JZEndRecord); i >= 0; i--) { http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/5f67db93/DocFormats/platform/tests/WrapperTests.c ---------------------------------------------------------------------- diff --git a/DocFormats/platform/tests/WrapperTests.c b/DocFormats/platform/tests/WrapperTests.c index 19ed4ae..daa5726 100644 --- a/DocFormats/platform/tests/WrapperTests.c +++ b/DocFormats/platform/tests/WrapperTests.c @@ -16,15 +16,17 @@ // under the License. #include "DFUnitTest.h" +#include "DFPlatform.h" #include static void test_DFextZipOpen(void) { -#if 0 - int DFextZipOpen(const char *zipFilename, int doUnzip) { -#endif + DFextZipHandleP zip; + + zip = DFextZipOpen("..\\test\\test.odx"); + zip = DFextZipOpen("..\\test\\test.odt"); }