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
This commit is contained in:
Ognyan Tonchev 2013-02-28 18:27:14 +01:00 committed by Colin Walters
parent 27b19cee1b
commit 06a59f889a
2 changed files with 12 additions and 4 deletions

View File

@ -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;
}

View File

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