Merged revisions 74167 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74167 | georg.brandl | 2009-07-22 13:57:15 +0200 (Mi, 22 Jul 2009) | 1 line

  Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
........
This commit is contained in:
Georg Brandl 2009-07-22 12:03:09 +00:00
parent 087d1a6d4b
commit 11a81b2151
3 changed files with 11 additions and 5 deletions

View file

@ -1469,6 +1469,11 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65) self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65) self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
def test_bytearray_translate(self):
x = bytearray("abc")
self.assertRaises(ValueError, x.translate, "1", 1)
self.assertRaises(TypeError, x.translate, "1"*256, 1)
class TestSorted(unittest.TestCase): class TestSorted(unittest.TestCase):
def test_basic(self): def test_basic(self):

View file

@ -12,6 +12,8 @@ What's New in Python 2.6.3
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
- Issue #6070: On posix platforms import no longer copies the execute bit - Issue #6070: On posix platforms import no longer copies the execute bit
from the .py file to the .pyc file if it is set. from the .py file to the .pyc file if it is set.

View file

@ -1458,15 +1458,14 @@ bytes_translate(PyByteArrayObject *self, PyObject *args)
if (vtable.len != 256) { if (vtable.len != 256) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"translation table must be 256 characters long"); "translation table must be 256 characters long");
result = NULL; PyBuffer_Release(&vtable);
goto done; return NULL;
} }
if (delobj != NULL) { if (delobj != NULL) {
if (_getbuffer(delobj, &vdel) < 0) { if (_getbuffer(delobj, &vdel) < 0) {
result = NULL; PyBuffer_Release(&vtable);
delobj = NULL; /* don't try to release vdel buffer on exit */ return NULL;
goto done;
} }
} }
else { else {