corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject incubator-corinthia git commit: Sort filenames before computing document hash
Date Sat, 25 Apr 2015 05:56:53 GMT
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.


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(-)
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
     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];
@@ -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;

View raw message