[Python-checkins] r74168 - in python/branches/release26-maint: Lib/test/test_builtin.py Misc/NEWS Objects/bytearrayobject.c

georg.brandl python-checkins at python.org
Wed Jul 22 14:03:09 CEST 2009


Author: georg.brandl
Date: Wed Jul 22 14:03:09 2009
New Revision: 74168

Log:
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.
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/test/test_builtin.py
   python/branches/release26-maint/Misc/NEWS
   python/branches/release26-maint/Objects/bytearrayobject.c

Modified: python/branches/release26-maint/Lib/test/test_builtin.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_builtin.py	(original)
+++ python/branches/release26-maint/Lib/test/test_builtin.py	Wed Jul 22 14:03:09 2009
@@ -1469,6 +1469,11 @@
         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):

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Wed Jul 22 14:03:09 2009
@@ -12,6 +12,8 @@
 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.
 

Modified: python/branches/release26-maint/Objects/bytearrayobject.c
==============================================================================
--- python/branches/release26-maint/Objects/bytearrayobject.c	(original)
+++ python/branches/release26-maint/Objects/bytearrayobject.c	Wed Jul 22 14:03:09 2009
@@ -1458,15 +1458,14 @@
     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 {


More information about the Python-checkins mailing list