[Python-bugs-list] [ python-Bugs-595671 ] base64.decodestring raises error on ""
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 15 Aug 2002 12:54:32 -0700
Bugs item #595671, was opened at 2002-08-15 14:27
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595671&group_id=5470
Category: Python Library
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Danny Yoo (dyoo)
Assigned to: Barry A. Warsaw (bwarsaw)
>Summary: base64.decodestring raises error on ""
Initial Comment:
The SOAPpy project uses base64.decodestring() to decode
base64-encoded strings. One issue that's been brought
up is the exception-raising behavior of decodestring()
if given the empty string in Python 2.2:
### In Python 2.2.1
>>> base64.decodestring("")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/opt/Python-2.2/lib/python2.2/base64.py", line
44, in decodestring
return binascii.a2b_base64(s)
binascii.Error: Cannot decode empty input
###
This is a behavioral change from Python 2.1.1, where it
had previously returned the empty string:
### Python 2.1.1
>>> base64.decodestring("")
""
###
This change seems to have been introduced in -r2.29 of
binascii.c. Is this the expected behavior of
decodestring() now?
For more information about our discussion on this,
please see the thread started here:
http://www.geocrawler.com/lists/3/SourceForge/12392/0/9289852/
Thanks again!
----------------------------------------------------------------------
>Comment By: Barry A. Warsaw (bwarsaw)
Date: 2002-08-15 15:54
Message:
Logged In: YES
user_id=12800
Attached is a patch candidate for Python 2.3cvs. I haven't
checked the backport to 2.2.2 yet, but its probably not much
different.
----------------------------------------------------------------------
Comment By: Barry A. Warsaw (bwarsaw)
Date: 2002-08-15 15:26
Message:
Logged In: YES
user_id=12800
Note that Python 2.1.3 has the same behavior as Python 2.2.
This behavior was introduced to fix SF bug #430849, but
that fix was actually incorrect. The SystemError (bad
internal call) was caused by trying to resize the empty
string, which is shared, and thus has a refcount != 1.
_PyString_Resize() requires the refcount of the string you
pass in to be == 1.
The proper fix should be to not resize the empty string in
binascii_a2b_base64() and to remove the exception raised in
the patch for #430849. I'll work out a patch for that and
upload it here. It will be a Python 2.2 bug fix candiate as
well.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=595671&group_id=5470