From: Thomas Wouters Date: Mon, 17 Mar 2003 11:34:43 +0000 (+0000) Subject: binascii_a2b_base64: Properly return an empty string if the input was all X-Git-Tag: v2.2.3c1~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5f77780f06b00954d7a159aa05f7ebb23808e14;p=thirdparty%2FPython%2Fcpython.git binascii_a2b_base64: Properly return an empty string if the input was all invalid, rather than returning a string of random garbage of the estimated result length. Closes SF patch #703471 by Hye-Shik Chang. Backport from 2.3. --- diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index c14f894c0d50..fc8336a3f62c 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -69,6 +69,10 @@ for line in map(addnoise, lines): res = res + b verify(res == testdata) +# Test base64 with just invalid characters, which should return +# empty strings. +verify(binascii.a2b_base64(fillers) == '') + # Test uu print "uu test" MAX_UU = 45 diff --git a/Modules/binascii.c b/Modules/binascii.c index 2b90789c7eb3..6a508a181b8a 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -411,6 +411,10 @@ binascii_a2b_base64(PyObject *self, PyObject *args) /* and set string size correctly */ if (bin_len > 0) _PyString_Resize(&rv, bin_len); + else { + Py_DECREF(rv); + return PyString_FromString(""); + } return rv; }