Commit 313cac88 authored by Victor Stinner's avatar Victor Stinner

Issue #17223: Fix PyUnicode_FromUnicode() on Windows (16-bit wchar_t type)

to reject invalid UTF-16 surrogate.
parent e5c0533b
...@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? ...@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #17223: Fix PyUnicode_FromUnicode() on Windows (16-bit wchar_t type)
to reject invalid UTF-16 surrogate.
- Issue #17032: The "global" in the "NameError: global name 'x' is not defined" - Issue #17032: The "global" in the "NameError: global name 'x' is not defined"
error message has been removed. Patch by Ram Rachum. error message has been removed. Patch by Ram Rachum.
......
...@@ -1384,14 +1384,19 @@ find_maxchar_surrogates(const wchar_t *begin, const wchar_t *end, ...@@ -1384,14 +1384,19 @@ find_maxchar_surrogates(const wchar_t *begin, const wchar_t *end,
for (iter = begin; iter < end; ) { for (iter = begin; iter < end; ) {
#if SIZEOF_WCHAR_T == 2 #if SIZEOF_WCHAR_T == 2
if (Py_UNICODE_IS_HIGH_SURROGATE(iter[0]) if (Py_UNICODE_IS_HIGH_SURROGATE(iter[0])) {
&& (iter+1) < end if ((iter+1) < end
&& Py_UNICODE_IS_LOW_SURROGATE(iter[1])) && Py_UNICODE_IS_LOW_SURROGATE(iter[1]))
{ {
ch = Py_UNICODE_JOIN_SURROGATES(iter[0], iter[1]); ch = Py_UNICODE_JOIN_SURROGATES(iter[0], iter[1]);
++(*num_surrogates); ++(*num_surrogates);
iter += 2; iter += 2;
} }
else {
PyErr_SetString(PyExc_ValueError, "illegal UTF-16 surrogate");
return -1;
}
}
else else
#endif #endif
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment