Skip to content

Commit 29ec595

Browse files
committed
Issue python#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.
1 parent d21b58c commit 29ec595

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎Lib/test/test_array.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,12 @@ def test_unicode(self):
10691069

10701070
self.assertRaises(TypeError, a.fromunicode)
10711071

1072+
def test_issue17223(self):
1073+
# this used to crash
1074+
a = array.array('u', b'\xff' * 4)
1075+
self.assertRaises(ValueError, a.tounicode)
1076+
self.assertRaises(ValueError, str, a)
1077+
10721078
class NumberTest(BaseTest):
10731079

10741080
def test_extslice(self):

‎Misc/NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.3.1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #17223: array module: Fix a crasher when converting an array containing
16+
invalid characters (outside range [U+0000; U+10ffff]) to Unicode:
17+
repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob.
18+
1519
- Issue #17223: Fix PyUnicode_FromUnicode() for string of 1 character outside
1620
the range U+0000-U+10ffff.
1721

‎Modules/arraymodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,8 @@ array_repr(arrayobject *a)
21802180
} else {
21812181
v = array_tolist(a, NULL);
21822182
}
2183+
if (v == NULL)
2184+
return NULL;
21832185

21842186
s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v);
21852187
Py_DECREF(v);

0 commit comments

Comments
 (0)