Commit c3c9db89 authored by Jay Bosamiya's avatar Jay Bosamiya Committed by Serhiy Storchaka

[2.7] bpo-30657: Check & prevent integer overflow in PyString_DecodeEscape (#2174)

parent 24c2c208
......@@ -152,6 +152,7 @@ Gregory Bond
Matias Bordese
Jonas Borgström
Jurjen Bos
Jay Bosamiya
Peter Bosch
Dan Boswell
Eric Bouck
......
......@@ -10,6 +10,9 @@ What's New in Python 2.7.14?
Core and Builtins
-----------------
- bpo-30657: Fixed possible integer overflow in PyString_DecodeEscape.
Patch by Jay Bosamiya.
- bpo-27945: Fixed various segfaults with dict when input collections are
mutated during searching, inserting or comparing. Based on patches by
Duane Griffin and Tim Mitchell.
......
......@@ -612,7 +612,13 @@ PyObject *PyString_DecodeEscape(const char *s,
char *p, *buf;
const char *end;
PyObject *v;
Py_ssize_t newlen = recode_encoding ? 4*len:len;
Py_ssize_t newlen;
/* Check for integer overflow */
if (recode_encoding && (len > PY_SSIZE_T_MAX / 4)) {
PyErr_SetString(PyExc_OverflowError, "string is too large");
return NULL;
}
newlen = recode_encoding ? 4*len:len;
v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment