Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes possible integer overflow in PyBytes_DecodeEscape.

Co-Authored-By: Jay Bosamiya <jaybosamiya@gmail.com>
  • Loading branch information
2 people authored and larryhastings committed Dec 8, 2017
1 parent dcb101e commit fd8614c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Médéric Boquien
Matias Bordese
Jonas Borgström
Jurjen Bos
Jay Bosamiya
Peter Bosch
Dan Boswell
Eric Bouck
Expand Down Expand Up @@ -651,6 +652,7 @@ Ken Howard
Brad Howes
Mike Hoy
Ben Hoyt
Miro Hrončok
Chiu-Hsiang Hsu
Chih-Hao Huang
Christian Hudon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed possible integer overflow in PyBytes_DecodeEscape, CVE-2017-1000158.
Original patch by Jay Bosamiya; rebased to Python 3 by Miro Hrončok.
8 changes: 7 additions & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,13 @@ PyObject *PyBytes_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 = PyBytes_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
Expand Down

0 comments on commit fd8614c

Please sign in to comment.