Skip to content

Commit 6154616

Browse files
committed
SF Bug #1454485, array.array('u') could crash the interpreter when
passing a string. Martin already fixed the actual crash by ensuring Py_UNICODE is unsigned. As discussed on python-dev, this fix removes the possibility of creating a unicode string from a raw buffer. There is an outstanding question of how to fix the crash in 2.4.
1 parent 384178c commit 6154616

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ What's New in Python 2.5 alpha 2?
1212
Core and builtins
1313
-----------------
1414

15+
- Bug #1454485, array.array('u') could crash the interpreter. This was
16+
due to PyArgs_ParseTuple(args, 'u#', ...) trying to convert buffers (strings)
17+
to unicode when it didn't make sense. 'u#' now requires a unicode string.
18+
19+
- Py_UNICODE is unsigned. It was always documented as unsigned, but
20+
due to a bug had a signed value in previous versions.
21+
1522
- Patch #837242: ``id()`` of any Python object always gives a positive
1623
number now, which might be a long integer. ``PyLong_FromVoidPtr`` and
1724
``PyLong_AsVoidPtr`` have been changed accordingly. Note that it has

Python/getargs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
10421042
STORE_SIZE(PyUnicode_GET_SIZE(arg));
10431043
}
10441044
else {
1045-
char *buf;
1046-
Py_ssize_t count = convertbuffer(arg, p, &buf);
1047-
if (count < 0)
1048-
return converterr(buf, arg, msgbuf, bufsize);
1049-
STORE_SIZE(count/(sizeof(Py_UNICODE)));
1045+
return converterr("cannot convert raw buffers",
1046+
arg, msgbuf, bufsize);
10501047
}
10511048
format++;
10521049
} else {

0 commit comments

Comments
 (0)