diff options
-rw-r--r-- | Lib/test/test_builtin.py | 5 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Objects/bytearrayobject.c | 9 |
3 files changed, 11 insertions, 5 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 6671f2c..910658d 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1469,6 +1469,11 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 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): def test_basic(self): @@ -12,6 +12,8 @@ What's New in Python 2.6.3 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 from the .py file to the .pyc file if it is set. diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index b5dd81b..7eafce7 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1458,15 +1458,14 @@ bytes_translate(PyByteArrayObject *self, PyObject *args) if (vtable.len != 256) { PyErr_SetString(PyExc_ValueError, "translation table must be 256 characters long"); - result = NULL; - goto done; + PyBuffer_Release(&vtable); + return NULL; } if (delobj != NULL) { if (_getbuffer(delobj, &vdel) < 0) { - result = NULL; - delobj = NULL; /* don't try to release vdel buffer on exit */ - goto done; + PyBuffer_Release(&vtable); + return NULL; } } else { |