diff options
author | Georg Brandl <georg@python.org> | 2010-08-01 08:49:18 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-01 08:49:18 (GMT) |
commit | bd534f03498c97273dc5bf00182e6405a3a92e01 (patch) | |
tree | f06866db483522693570fa00a07d653fc3b6b39b /Objects/unicodeobject.c | |
parent | 9411eeb522980f6239e5466a23417cdd8e6149a1 (diff) | |
download | cpython-bd534f03498c97273dc5bf00182e6405a3a92e01.zip cpython-bd534f03498c97273dc5bf00182e6405a3a92e01.tar.gz cpython-bd534f03498c97273dc5bf00182e6405a3a92e01.tar.bz2 |
#8821: do not rely on Unicode strings being terminated with a \u0000, rather explicitly check range before looking for a second surrogate character.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f2d666d..bfd19eb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3734,7 +3734,7 @@ PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s, ch2 = *s++; size--; - if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF && size) { ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000; *p++ = '\\'; *p++ = 'U'; @@ -3976,7 +3976,7 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s, ch2 = *s++; size--; - if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF && size) { ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000; *p++ = '\\'; *p++ = 'U'; |