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 ...@@ -152,6 +152,7 @@ Gregory Bond
Matias Bordese Matias Bordese
Jonas Borgström Jonas Borgström
Jurjen Bos Jurjen Bos
Jay Bosamiya
Peter Bosch Peter Bosch
Dan Boswell Dan Boswell
Eric Bouck Eric Bouck
......
...@@ -10,6 +10,9 @@ What's New in Python 2.7.14? ...@@ -10,6 +10,9 @@ What's New in Python 2.7.14?
Core and Builtins 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 - bpo-27945: Fixed various segfaults with dict when input collections are
mutated during searching, inserting or comparing. Based on patches by mutated during searching, inserting or comparing. Based on patches by
Duane Griffin and Tim Mitchell. Duane Griffin and Tim Mitchell.
......
...@@ -612,7 +612,13 @@ PyObject *PyString_DecodeEscape(const char *s, ...@@ -612,7 +612,13 @@ PyObject *PyString_DecodeEscape(const char *s,
char *p, *buf; char *p, *buf;
const char *end; const char *end;
PyObject *v; 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); v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL) if (v == NULL)
return 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