Skip to content

Commit 25c3053

Browse files
committed
(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.
2 parents 3602547 + 29ec595 commit 25c3053

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

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
@@ -10,6 +10,10 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

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

Modules/arraymodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,8 @@ array_repr(arrayobject *a)
21772177
} else {
21782178
v = array_tolist(a, NULL);
21792179
}
2180+
if (v == NULL)
2181+
return NULL;
21802182

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

0 commit comments

Comments
 (0)