diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-09-30 03:02:56 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-09-30 03:02:56 (GMT) |
commit | fd97a6fb2d501f0ecb104513b5c0c1707dd6f87e (patch) | |
tree | d4d43de4c1a506173f669af209e539fa7c5176f8 | |
parent | 58ee2d31ab2dc039c6929347bf6cfb0cfd827198 (diff) | |
parent | 43030ee78041455566e7f78d6d5135eaa3455294 (diff) | |
download | cpython-fd97a6fb2d501f0ecb104513b5c0c1707dd6f87e.zip cpython-fd97a6fb2d501f0ecb104513b5c0c1707dd6f87e.tar.gz cpython-fd97a6fb2d501f0ecb104513b5c0c1707dd6f87e.tar.bz2 |
merge 3.4 (#22520)
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 28 |
2 files changed, 20 insertions, 11 deletions
@@ -10,6 +10,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #22520: Fix overflow checking when generating the repr of a unicode + object. + - Issue #22519: Fix overflow checking in PyBytes_Repr. - Issue #22518: Fix integer overflow issues in latin-1 encoding. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 085798a..44f714e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12365,28 +12365,34 @@ unicode_repr(PyObject *unicode) ikind = PyUnicode_KIND(unicode); for (i = 0; i < isize; i++) { Py_UCS4 ch = PyUnicode_READ(ikind, idata, i); + Py_ssize_t incr = 1; switch (ch) { - case '\'': squote++; osize++; break; - case '"': dquote++; osize++; break; + case '\'': squote++; break; + case '"': dquote++; break; case '\\': case '\t': case '\r': case '\n': - osize += 2; break; + incr = 2; + break; default: /* Fast-path ASCII */ if (ch < ' ' || ch == 0x7f) - osize += 4; /* \xHH */ + incr = 4; /* \xHH */ else if (ch < 0x7f) - osize++; - else if (Py_UNICODE_ISPRINTABLE(ch)) { - osize++; + ; + else if (Py_UNICODE_ISPRINTABLE(ch)) max = ch > max ? ch : max; - } else if (ch < 0x100) - osize += 4; /* \xHH */ + incr = 4; /* \xHH */ else if (ch < 0x10000) - osize += 6; /* \uHHHH */ + incr = 6; /* \uHHHH */ else - osize += 10; /* \uHHHHHHHH */ + incr = 10; /* \uHHHHHHHH */ + } + if (osize > PY_SSIZE_T_MAX - incr) { + PyErr_SetString(PyExc_OverflowError, + "string is too long to generate repr"); + return NULL; } + osize += incr; } quote = '\''; |