Merged revisions 77506 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77506 | antoine.pitrou | 2010-01-15 01:18:00 +0100 (ven., 15 janv. 2010) | 4 lines
Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
1-byte argument. Patch by Victor Stinner.
........
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index ea8be31..4ebf429 100755
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -104,6 +104,9 @@
self.assertRaises(binascii.Error, binascii.b2a_uu, 46*"!")
+ # Issue #7701 (crash on a pydebug build)
+ self.assertEqual(binascii.b2a_uu('x'), '!> \n')
+
def test_crc32(self):
crc = binascii.crc32("Test the CRC-32 of")
crc = binascii.crc32(" this string.", crc)
diff --git a/Misc/NEWS b/Misc/NEWS
index a292c74..c9b15b0 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,9 @@
Library
-------
+- Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
+ 1-byte argument. Patch by Victor Stinner.
+
- Issue #3299: Fix possible crash in the _sre module when given bad
argument values in debug mode. Patch by Victor Stinner.
diff --git a/Modules/binascii.c b/Modules/binascii.c
index bcbafcf..65471a6 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -282,7 +282,7 @@
}
/* We're lazy and allocate to much (fixed up later) */
- if ( (rv=PyString_FromStringAndSize(NULL, bin_len*2+2)) == NULL )
+ if ( (rv=PyString_FromStringAndSize(NULL, 2 + (bin_len+2)/3*4)) == NULL )
return NULL;
ascii_data = (unsigned char *)PyString_AsString(rv);