[Python-checkins] cpython (merge 3.3 -> default): (Merge 3.3) Issue #17223: array module: Fix a crasher when converting an array

victor.stinner python-checkins at python.org
Tue Feb 26 00:28:55 CET 2013


http://hg.python.org/cpython/rev/381de621ff6a
changeset:   82389:381de621ff6a
parent:      82387:a4295ab52427
parent:      82388:ebeed44702ec
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Feb 26 00:27:56 2013 +0100
summary:
  (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.

files:
  Lib/test/test_array.py |  6 ++++++
  Misc/NEWS              |  4 ++++
  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
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -1069,6 +1069,12 @@
 
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 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
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2177,6 +2177,8 @@
     } else {
         v = array_tolist(a, NULL);
     }
+    if (v == NULL)
+        return NULL;
 
     s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v);
     Py_DECREF(v);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list