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 C410B17274 for ; Sat, 25 Apr 2015 05:57:18 +0000 (UTC) Received: (qmail 52478 invoked by uid 500); 25 Apr 2015 05:57:18 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 52460 invoked by uid 500); 25 Apr 2015 05:57:18 -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 52449 invoked by uid 99); 25 Apr 2015 05:57:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Apr 2015 05:57:18 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of root@apache.org designates 54.191.145.13 as permitted sender) Received: from [54.191.145.13] (HELO mx1-us-west.apache.org) (54.191.145.13) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Apr 2015 05:57:14 +0000 Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 0E50D2064A for ; Sat, 25 Apr 2015 05:56:54 +0000 (UTC) Received: (qmail 52416 invoked by uid 99); 25 Apr 2015 05:56:53 -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; Sat, 25 Apr 2015 05:56:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D87F2E0979; Sat, 25 Apr 2015 05:56:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: pmkelly@apache.org To: commits@corinthia.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-corinthia git commit: Sort filenames before computing document hash Date: Sat, 25 Apr 2015 05:56:53 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-corinthia Updated Branches: refs/heads/master ff4dfff2a -> 143b78308 Sort filenames before computing document hash When computing the hash of all files in a document package, ensure that we process each file in alphabetical order, to guarantee that the hash will be the same when this process is done twice for the same document. There is no guarantee that DFStorageList will return filenames in the same order each time. In practice, the current implementation of DFStorageList *does* return them in the same order, however this is only out of luck. This is due to the current implementation of DFHashTable, and the way that its contents are populated when reading a zip file. However, this implementation could change in in the future, so sorting the results is necessary if we want to guarantee the ordering. Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/143b7830 Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/143b7830 Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/143b7830 Branch: refs/heads/master Commit: 143b78308812f56fa39cd886e3fb65169ce0fe84 Parents: ff4dfff Author: Peter Kelly Authored: Sat Apr 25 12:53:08 2015 +0700 Committer: Peter Kelly Committed: Sat Apr 25 12:56:38 2015 +0700 ---------------------------------------------------------------------- DocFormats/api/src/Operations.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/143b7830/DocFormats/api/src/Operations.c ---------------------------------------------------------------------- diff --git a/DocFormats/api/src/Operations.c b/DocFormats/api/src/Operations.c index a9f9bb2..62b6e7b 100644 --- a/DocFormats/api/src/Operations.c +++ b/DocFormats/api/src/Operations.c @@ -42,7 +42,7 @@ struct DFAbstractDocument { }; /** - * Compute a hash of the set of all XML files in the archive. When the get operation is executed, + * Compute a hash of the set of all files in the archive. When the get operation is executed, * this hash is stored in the HTML file, as a record of the document from which it was generated. * When the put operation is executed, the hash is compared with that of the HTML file, and an error * reported if a mismatch occurs. @@ -55,7 +55,7 @@ struct DFAbstractDocument { * If someone tries to call put with a HTML document that was not originally created from this exact * concrete document, the operation will fail. */ -static int computeXMLHash(DFStorage *storage, DFHashCode *result, DFError **error) +static int computeDocumentHash(DFStorage *storage, DFHashCode *result, DFError **error) { int ok = 0; *result = 0; @@ -65,6 +65,7 @@ static int computeXMLHash(DFStorage *storage, DFHashCode *result, DFError **erro const char **filenames = DFStorageList(storage,error); if (filenames == NULL) goto end; + DFSortStringsCaseSensitive(filenames); for (int i = 0; filenames[i]; i++) { unsigned char *buf = NULL; size_t nbytes = 0; @@ -219,7 +220,7 @@ int DFGet(DFConcreteDocument *concrete, } DFHashCode hash = 0; - if (!computeXMLHash(concrete->storage,&hash,error)) + if (!computeDocumentHash(concrete->storage,&hash,error)) return 0; char hashstr[100]; snprintf(hashstr,100,"%X",hash); @@ -277,7 +278,7 @@ int DFPut(DFConcreteDocument *concreteDoc, // and can rely on the element mappings from the id attributes. This comparison is ignored // for test cases, which specify the special value "ignore" in the meta tag. DFHashCode expectedHash = 0; - if (!computeXMLHash(concreteDoc->storage,&expectedHash,error)) + if (!computeDocumentHash(concreteDoc->storage,&expectedHash,error)) return 0;; DFHashCode actualHash = 0; int hashMatches = 0;