]> granicus.if.org Git - python/commitdiff
Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jan 2010 00:18:00 +0000 (00:18 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 15 Jan 2010 00:18:00 +0000 (00:18 +0000)
1-byte argument.  Patch by Victor Stinner.

Lib/test/test_binascii.py
Misc/NEWS
Modules/binascii.c

index c8fad5809b4c8f1f07eedbf81678c2e841d9e60a..b73f1197bb70f667bbf2b03014e14e2942b64fd9 100755 (executable)
@@ -109,6 +109,9 @@ class BinASCIITest(unittest.TestCase):
 
         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)
index 16f1cdb4f585555f747bd8307632c06cc5016ebe..5db6e70a5051bcab14359c832c98e217a3fccac8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
 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.
 
index 24d20e41816f4867c83ac92dd0f3c8d5c63607d7..cf027431fa6d2d2fe4349ec390790eee9ce5bdea 100644 (file)
@@ -294,7 +294,7 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
        }
 
        /* 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 ) {
                PyBuffer_Release(&pbin);
                return NULL;
        }