gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: implement decompression logic


From: gnunet
Subject: [taler-anastasis] branch master updated: implement decompression logic
Date: Sat, 06 Feb 2021 16:00:40 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 287e0de  implement decompression logic
287e0de is described below

commit 287e0de9e3811dc754686a716622958d4f8b2291
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Feb 6 16:00:38 2021 +0100

    implement decompression logic
---
 src/include/anastasis.h      | 10 ++++++++
 src/lib/anastasis_backup.c   | 11 ++++++---
 src/lib/anastasis_recovery.c | 58 +++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index a94093c..2ab95bb 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -115,6 +115,16 @@ enum ANASTASIS_RecoveryStatus
    */
   ANASTASIS_RS_POLICY_DOWNLOAD_NO_POLICY,
 
+  /**
+   * The decompressed policy document was too big for available memory.
+   */
+  ANASTASIS_RS_POLICY_DOWNLOAD_TOO_BIG,
+
+  /**
+   * The decrypted policy document was not compressed.
+   */
+  ANASTASIS_RS_POLICY_DOWNLOAD_INVALID_COMPRESSION,
+
   /**
    * The decompressed policy document was not in JSON.
    */
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index 2b9813b..b4b5aad 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -842,6 +842,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     Bytef *cbuf;
     uLongf cbuf_size;
     int ret;
+    uint32_t be_size;
 
     recovery_document = json_pack (
       "{s:o, s:o, s:o}",
@@ -858,8 +859,12 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     json_decref (recovery_document);
     rd_size = strlen (rd_str);
     cbuf_size = compressBound (rd_size);
-    cbuf = GNUNET_malloc (cbuf_size);
-    ret = compress (cbuf,
+    be_size = htonl ((uint32_t) rd_size);
+    cbuf = GNUNET_malloc (cbuf_size + sizeof (uint32_t));
+    memcpy (cbuf,
+            &be_size,
+            sizeof (uint32_t));
+    ret = compress (cbuf + sizeof (uint32_t),
                     &cbuf_size,
                     (const Bytef *) rd_str,
                     rd_size);
@@ -873,7 +878,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       return NULL;
     }
     free (rd_str);
-    recovery_document_size = (size_t) cbuf_size;
+    recovery_document_size = (size_t) (cbuf_size + sizeof (uint32_t));
     recovery_document_str = (char *) cbuf;
   }
 
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index da8dc7a..193d457 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -23,6 +23,7 @@
 #include <taler/taler_json_lib.h>
 #include <gnunet/gnunet_util_lib.h>
 #include <taler/taler_merchant_service.h>
+#include <zlib.h>
 
 
 /**
@@ -694,16 +695,61 @@ policy_lookup_cb (void *cls,
                                               dd->policy_size,
                                               &plaintext,
                                               &size_plaintext);
-  // FIXME: DECOMPRESSION
-
+  if (size_plaintext < sizeof (uint32_t))
+  {
+    GNUNET_break_op (0);
+    r->csc (r->csc_cls,
+            ANASTASIS_RS_POLICY_DOWNLOAD_INVALID_COMPRESSION,
+            NULL,
+            0);
+    ANASTASIS_recovery_abort (r);
+    GNUNET_free (plaintext);
+    return;
+  }
   {
     json_t *recovery_document;
-
-    recovery_document = json_loadb ((char *) plaintext,
-                                    size_plaintext,
+    uint32_t be_size;
+    uLongf pt_size;
+    char *pt;
+
+    memcpy (&be_size,
+            plaintext,
+            sizeof (uint32_t));
+    pt_size = ntohl (be_size);
+    pt = GNUNET_malloc_large (pt_size);
+    if (NULL == pt)
+    {
+      GNUNET_break_op (0);
+      r->csc (r->csc_cls,
+              ANASTASIS_RS_POLICY_DOWNLOAD_TOO_BIG,
+              NULL,
+              0);
+      ANASTASIS_recovery_abort (r);
+      GNUNET_free (plaintext);
+      return;
+    }
+    if (Z_OK !=
+        uncompress ((Bytef *) pt,
+                    &pt_size,
+                    (const Bytef *) plaintext,
+                    size_plaintext))
+    {
+      GNUNET_break_op (0);
+      r->csc (r->csc_cls,
+              ANASTASIS_RS_POLICY_DOWNLOAD_INVALID_COMPRESSION,
+              NULL,
+              0);
+      GNUNET_free (plaintext);
+      GNUNET_free (pt);
+      ANASTASIS_recovery_abort (r);
+      return;
+    }
+    GNUNET_free (plaintext);
+    recovery_document = json_loadb ((char *) pt,
+                                    pt_size,
                                     JSON_DECODE_ANY,
                                     &json_error);
-    GNUNET_free (plaintext);
+    GNUNET_free (pt);
     if (NULL == recovery_document)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]