mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-25 03:32:12 +01:00
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:
parent
27b19cee1b
commit
06a59f889a
@ -344,8 +344,18 @@ g_base64_decode_step (const gchar *in,
|
|||||||
/* convert 4 base64 bytes to 3 normal bytes */
|
/* convert 4 base64 bytes to 3 normal bytes */
|
||||||
v=*save;
|
v=*save;
|
||||||
i=*state;
|
i=*state;
|
||||||
inptr = (const guchar *)in;
|
|
||||||
last[0] = last[1] = 0;
|
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)
|
while (inptr < inend)
|
||||||
{
|
{
|
||||||
c = *inptr++;
|
c = *inptr++;
|
||||||
@ -369,7 +379,7 @@ g_base64_decode_step (const gchar *in,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*save = v;
|
*save = v;
|
||||||
*state = i;
|
*state = last[0] == '=' ? -i : i;
|
||||||
|
|
||||||
return outptr - out;
|
return outptr - out;
|
||||||
}
|
}
|
||||||
|
@ -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/decode-inplace", test_base64_decode_inplace);
|
||||||
g_test_add_func ("/base64/encode-decode", test_base64_encode_decode);
|
g_test_add_func ("/base64/encode-decode", test_base64_encode_decode);
|
||||||
|
|
||||||
/*
|
|
||||||
g_test_add_data_func ("/base64/incremental/smallblock/1", GINT_TO_POINTER(1),
|
g_test_add_data_func ("/base64/incremental/smallblock/1", GINT_TO_POINTER(1),
|
||||||
test_base64_decode_smallblock);
|
test_base64_decode_smallblock);
|
||||||
g_test_add_data_func ("/base64/incremental/smallblock/2", GINT_TO_POINTER(2),
|
g_test_add_data_func ("/base64/incremental/smallblock/2", GINT_TO_POINTER(2),
|
||||||
test_base64_decode_smallblock);
|
test_base64_decode_smallblock);
|
||||||
g_test_add_data_func ("/base64/incremental/smallblock/3", GINT_TO_POINTER(3),
|
g_test_add_data_func ("/base64/incremental/smallblock/3", GINT_TO_POINTER(3),
|
||||||
test_base64_decode_smallblock);
|
test_base64_decode_smallblock);
|
||||||
*/
|
|
||||||
g_test_add_data_func ("/base64/incremental/smallblock/4", GINT_TO_POINTER(4),
|
g_test_add_data_func ("/base64/incremental/smallblock/4", GINT_TO_POINTER(4),
|
||||||
test_base64_decode_smallblock);
|
test_base64_decode_smallblock);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user