From: Antoine Pitrou Date: Fri, 15 Jan 2010 00:18:00 +0000 (+0000) Subject: Issue #7701: Fix crash in binascii.b2a_uu() in debug mode when given a X-Git-Tag: v2.7a3~150 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c391ad007b13ad781ab19c522168e86313706804;p=python 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 c8fad5809b..b73f1197bb 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 16f1cdb4f5..5db6e70a50 100644 --- 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. diff --git a/Modules/binascii.c b/Modules/binascii.c index 24d20e4181..cf027431fa 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -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; }