cpython: 0f1c2e2b6bc2 (original) (raw)
Mercurial > cpython
changeset 82051:0f1c2e2b6bc2 3.2
Issue #17043: The unicode-internal decoder no longer read past the end of input buffer. [#17043]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Thu, 07 Feb 2013 16:23:21 +0200 |
parents | 148e6ebfe854 |
children | fec2976c8503 55a89352e220 |
files | Misc/NEWS Objects/unicodeobject.c |
diffstat | 2 files changed, 27 insertions(+), 27 deletions(-)[+] [-] Misc/NEWS 3 Objects/unicodeobject.c 51 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.4 Core and Builtins ----------------- +- Issue #17043: The unicode-internal decoder no longer read past the end of
- Issue #16979: Fix error handling bugs in the unicode-escape-decode decoder.
- Issue #10156: In the interpreter's initialization phase, unicode globals
--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4392,37 +4392,34 @@ PyObject *_PyUnicode_DecodeUnicodeIntern end = s + size; while (s < end) {
if (end-s < Py_UNICODE_SIZE) {[](#l2.7)
endinpos = end-starts;[](#l2.8)
reason = "truncated input";[](#l2.9)
goto error;[](#l2.10)
}[](#l2.11) memcpy(p, s, sizeof(Py_UNICODE));[](#l2.12)
+#ifdef Py_UNICODE_WIDE /* We have to sanity check the raw data, otherwise doom looms for some malformed UCS-4 data. */
if ([](#l2.16)
*p > unimax || *p < 0 ||[](#l2.18)
if (*p > unimax || *p < 0) {[](#l2.19)
endinpos = s - starts + Py_UNICODE_SIZE;[](#l2.20)
reason = "illegal code point (> 0x10FFFF)";[](#l2.21)
goto error;[](#l2.22)
}[](#l2.23)
end-s < Py_UNICODE_SIZE[](#l2.25)
)[](#l2.26)
{[](#l2.27)
startinpos = s - starts;[](#l2.28)
if (end-s < Py_UNICODE_SIZE) {[](#l2.29)
endinpos = end-starts;[](#l2.30)
reason = "truncated input";[](#l2.31)
}[](#l2.32)
else {[](#l2.33)
endinpos = s - starts + Py_UNICODE_SIZE;[](#l2.34)
reason = "illegal code point (> 0x10FFFF)";[](#l2.35)
}[](#l2.36)
outpos = p - PyUnicode_AS_UNICODE(v);[](#l2.37)
if (unicode_decode_call_errorhandler([](#l2.38)
errors, &errorHandler,[](#l2.39)
"unicode_internal", reason,[](#l2.40)
&starts, &end, &startinpos, &endinpos, &exc, &s,[](#l2.41)
&v, &outpos, &p)) {[](#l2.42)
goto onError;[](#l2.43)
}[](#l2.44)
}[](#l2.45)
else {[](#l2.46)
p++;[](#l2.47)
s += Py_UNICODE_SIZE;[](#l2.48)
p++;[](#l2.49)
s += Py_UNICODE_SIZE;[](#l2.50)
continue;[](#l2.51)
- error:
startinpos = s - starts;[](#l2.54)
outpos = p - PyUnicode_AS_UNICODE(v);[](#l2.55)
if (unicode_decode_call_errorhandler([](#l2.56)
errors, &errorHandler,[](#l2.57)
"unicode_internal", reason,[](#l2.58)
&starts, &end, &startinpos, &endinpos, &exc, &s,[](#l2.59)
&v, &outpos, &p)) {[](#l2.60)
}goto onError;[](#l2.61) }[](#l2.62)