From: Victor Stinner Date: Mon, 25 Feb 2013 23:27:38 +0000 (+0100) Subject: Issue #17223: array module: Fix a crasher when converting an array containing X-Git-Tag: v3.3.1rc1~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29ec595c6a705428784d24eb7e03681637c4eb03;p=python 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. --- diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index a532a9fd2b..bfef4fac5a 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index 40c4825792..89cbcb59e1 100644 --- 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. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index adc4d5d865..96c9e5bba7 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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);