diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-03-05 23:41:50 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-03-05 23:41:50 (GMT) |
commit | 313cac88c524dd1d3c9810109de3f9c310d73413 (patch) | |
tree | de252eb9b34fe5be72a84785175975fb408723ed /Objects/unicodeobject.c | |
parent | e5c0533b5887fae64df7bf0d69a307f0a63c77e5 (diff) | |
download | cpython-313cac88c524dd1d3c9810109de3f9c310d73413.zip cpython-313cac88c524dd1d3c9810109de3f9c310d73413.tar.gz cpython-313cac88c524dd1d3c9810109de3f9c310d73413.tar.bz2 |
Issue #17223: Fix PyUnicode_FromUnicode() on Windows (16-bit wchar_t type)
to reject invalid UTF-16 surrogate.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2175655..00a6a36 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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 |