mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Issue #17223: Fix PyUnicode_FromUnicode() on Windows (16-bit wchar_t type)
to reject invalid UTF-16 surrogate.
This commit is contained in:
parent
e5c0533b58
commit
313cac88c5
2 changed files with 15 additions and 7 deletions
|
@ -1384,13 +1384,18 @@ find_maxchar_surrogates(const wchar_t *begin, const wchar_t *end,
|
|||
|
||||
for (iter = begin; iter < end; ) {
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
if (Py_UNICODE_IS_HIGH_SURROGATE(iter[0])
|
||||
&& (iter+1) < end
|
||||
&& Py_UNICODE_IS_LOW_SURROGATE(iter[1]))
|
||||
{
|
||||
ch = Py_UNICODE_JOIN_SURROGATES(iter[0], iter[1]);
|
||||
++(*num_surrogates);
|
||||
iter += 2;
|
||||
if (Py_UNICODE_IS_HIGH_SURROGATE(iter[0])) {
|
||||
if ((iter+1) < end
|
||||
&& Py_UNICODE_IS_LOW_SURROGATE(iter[1]))
|
||||
{
|
||||
ch = Py_UNICODE_JOIN_SURROGATES(iter[0], iter[1]);
|
||||
++(*num_surrogates);
|
||||
iter += 2;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "illegal UTF-16 surrogate");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue