[glib] base64: Fix g_base64_decode_step ()



commit 06a59f889a8d3c8a63622af64d253632a0530017
Author: Ognyan Tonchev <ognyan axis com>
Date:   Thu Feb 28 18:27:14 2013 +0100

    base64: Fix g_base64_decode_step ()
    
    Do not produce invalid data if there was padding character in the
    previous sequence.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694843

 glib/gbase64.c      |   14 ++++++++++++--
 glib/tests/base64.c |    2 --
 2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/glib/gbase64.c b/glib/gbase64.c
index d0ab0ea..bcc59a6 100644
--- a/glib/gbase64.c
+++ b/glib/gbase64.c
@@ -344,8 +344,18 @@ g_base64_decode_step (const gchar  *in,
   /* convert 4 base64 bytes to 3 normal bytes */
   v=*save;
   i=*state;
-  inptr = (const guchar *)in;
+
   last[0] = last[1] = 0;
+
+  /* we use the sign in the state to determine if we got a padding character
+     in the previous sequence */
+  if (i < 0)
+    {
+      i = -i;
+      last[0] = '=';
+    }
+
+  inptr = (const guchar *)in;
   while (inptr < inend)
     {
       c = *inptr++;
@@ -369,7 +379,7 @@ g_base64_decode_step (const gchar  *in,
     }
 
   *save = v;
-  *state = i;
+  *state = last[0] == '=' ? -i : i;
 
   return outptr - out;
 }
diff --git a/glib/tests/base64.c b/glib/tests/base64.c
index 0d8ce92..6704c44 100644
--- a/glib/tests/base64.c
+++ b/glib/tests/base64.c
@@ -408,14 +408,12 @@ main (int argc, char *argv[])
   g_test_add_func ("/base64/decode-inplace", test_base64_decode_inplace);
   g_test_add_func ("/base64/encode-decode", test_base64_encode_decode);
 
-  /*
   g_test_add_data_func ("/base64/incremental/smallblock/1", GINT_TO_POINTER(1),
                         test_base64_decode_smallblock);
   g_test_add_data_func ("/base64/incremental/smallblock/2", GINT_TO_POINTER(2),
                         test_base64_decode_smallblock);
   g_test_add_data_func ("/base64/incremental/smallblock/3", GINT_TO_POINTER(3),
                         test_base64_decode_smallblock);
-  */
   g_test_add_data_func ("/base64/incremental/smallblock/4", GINT_TO_POINTER(4),
                         test_base64_decode_smallblock);
 


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