From 0c25da5823de33210dc43c3c30d51a995d752fce Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 15 Aug 2002 22:18:11 +0000 Subject: [PATCH] Backport of fix for SF bug #595671 from Python 2.3cvs: base64.decodestring('') should return '' instead of raising an exception. The bug fix for SF #430849 wasn't quite right. This closes SF bug #595671. I'll backport this to Python 2.2. One addition here is that there was no test of the base64 module in Python 2.2 cvs yet, so I added that too. --- Lib/test/output/test_base64 | 8 ++++++++ Modules/binascii.c | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 Lib/test/output/test_base64 diff --git a/Lib/test/output/test_base64 b/Lib/test/output/test_base64 new file mode 100644 index 000000000000..ec6ac2b97182 --- /dev/null +++ b/Lib/test/output/test_base64 @@ -0,0 +1,8 @@ +test_base64 +Testing decode string ... ok +Testing encode string ... ok + +---------------------------------------------------------------------- +Ran 2 tests in 0.001s + +OK diff --git a/Modules/binascii.c b/Modules/binascii.c index 9ef305414f31..70d60f024886 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -346,10 +346,6 @@ binascii_a2b_base64(PyObject *self, PyObject *args) if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) ) return NULL; - if ( ascii_len == 0) { - PyErr_SetString(Error, "Cannot decode empty input"); - return NULL; - } bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */ /* Allocate the buffer */ @@ -413,7 +409,8 @@ binascii_a2b_base64(PyObject *self, PyObject *args) } /* and set string size correctly */ - _PyString_Resize(&rv, bin_len); + if (bin_len > 0) + _PyString_Resize(&rv, bin_len); return rv; } -- 2.47.3