]> granicus.if.org Git - python/commitdiff
Issue #17223: array module: Fix a crasher when converting an array containing
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Feb 2013 23:27:38 +0000 (00:27 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Feb 2013 23:27:38 +0000 (00:27 +0100)
invalid characters (outside range [U+0000; U+10ffff]) to Unicode: repr(array),
str(array) and array.tounicode(). Patch written by Manuel Jacob.

Lib/test/test_array.py
Misc/NEWS
Modules/arraymodule.c

index a532a9fd2bd18f04f5ab59c129a8f608cefa6781..bfef4fac5a56a6ae762893d83601373bd64e93a2 100755 (executable)
@@ -1069,6 +1069,12 @@ class UnicodeTest(StringTest, unittest.TestCase):
 
         self.assertRaises(TypeError, a.fromunicode)
 
+    def test_issue17223(self):
+        # this used to crash
+        a = array.array('u', b'\xff' * 4)
+        self.assertRaises(ValueError, a.tounicode)
+        self.assertRaises(ValueError, str, a)
+
 class NumberTest(BaseTest):
 
     def test_extslice(self):
index 40c4825792e925d9369bb774f17bb2061a5fadbb..89cbcb59e1ad2a8b7872348cfe1b883583265be2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 3.3.1?
 Core and Builtins
 -----------------
 
+- Issue #17223: array module: Fix a crasher when converting an array containing
+  invalid characters (outside range [U+0000; U+10ffff]) to Unicode:
+  repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob.
+
 - Issue #17223: Fix PyUnicode_FromUnicode() for string of 1 character outside
   the range U+0000-U+10ffff.
 
index adc4d5d86502e516fd10171c55d2fe007517cb6e..96c9e5bba75f9d253216b219b56163e228691a3a 100644 (file)
@@ -2180,6 +2180,8 @@ array_repr(arrayobject *a)
     } else {
         v = array_tolist(a, NULL);
     }
+    if (v == NULL)
+        return NULL;
 
     s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v);
     Py_DECREF(v);