diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-02-25 23:27:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-02-25 23:27:56 (GMT) |
commit | 25c3053a4f65fecaa7dfcabdbd7627a425d1a812 (patch) | |
tree | 8618dd858dd7495689ec674a1d1569a37c1a3df2 | |
parent | 36025478bff1012dbb6d9312aca4a798ee089e8e (diff) | |
parent | 29ec595c6a705428784d24eb7e03681637c4eb03 (diff) | |
download | cpython-25c3053a4f65fecaa7dfcabdbd7627a425d1a812.zip cpython-25c3053a4f65fecaa7dfcabdbd7627a425d1a812.tar.gz cpython-25c3053a4f65fecaa7dfcabdbd7627a425d1a812.tar.bz2 |
(Merge 3.3) 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.
-rwxr-xr-x | Lib/test/test_array.py | 6 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Modules/arraymodule.c | 2 |
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 8b934fc..b024276 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): @@ -10,6 +10,10 @@ What's New in Python 3.4.0 Alpha 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 a0e89d4..1c75989 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2177,6 +2177,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); |