[Python-bugs-list] [ python-Bugs-494738 ] binascii_b2a_base64 overwrites memory

noreply@sourceforge.net noreply@sourceforge.net
Tue, 18 Dec 2001 11:55:19 -0800


Bugs item #494738, was opened at 2001-12-18 11:55
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=494738&group_id=5470

Category: Python Library
Group: Not a Bug
Status: Open
Resolution: None
Priority: 5
Submitted By: David Costanzo (david_costanzo)
Assigned to: Nobody/Anonymous (nobody)
Summary: binascii_b2a_base64 overwrites memory

Initial Comment:
I'm maintaining code that is based on the binascii.c 
found in Python-2.1.1/Modules directory (Python 2.1..  
The code has a memory bounds overwrite when encoding 
binascii_b2a_base64 for small chunks of binary data.

The bug in my code is that allocates an incorrect 
upper bound.  For each byte of binary data, it 
allocates two bytes for the ascii format.  It looks 
like it really needs four bytes of binary data for 
every three bytes of binary data, rounded up, plus one 
byte for the courtesy newline.  The analogous line of 
code in binascii.c is line 425.

As a test case, the ascii representation of the one 
byte binary string 'b' takes five characters 'Yg==\n', 
not twice the lenght of the original.  (There are two 
two bytes of signal, two pad bytes, and a courtesy 
newline.)  My code now uses ((bin_len + 2) / 3) * 4 + 
1) as the buffer length.

I ran Python 2.0 under a heap validator program called 
Purify and attempted to reproduce the memory 
overwrite, but I was unable to.  This probably means 
that this bug does not exist in Python.  I am 
submitting it as a bug anyway, in case Python is using 
a memory heap that confuses Purify.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=494738&group_id=5470