From 3ce5d9207e66d61d4b0502cf47ed2d2bcdd2212f Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 24 Aug 2008 07:08:55 +0000 Subject: Closes release blocker #3627. Merged revisions 65335 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt) ........ r65335 | neal.norwitz | 2008-07-31 10:17:14 -0700 (Thu, 31 Jul 2008) | 1 line Security patches from Apple: prevent int overflow when allocating memory ........ --- Objects/bytesobject.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Objects/bytesobject.c') diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index bfb4ff8fd3..24228eae96 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -83,6 +83,12 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size) return (PyObject *)op; } + if (size > PY_SSIZE_T_MAX - sizeof(PyBytesObject)) { + PyErr_SetString(PyExc_OverflowError, + "byte string is too large"); + return NULL; + } + /* Inline PyObject_NewVar */ op = (PyBytesObject *)PyObject_MALLOC(sizeof(PyBytesObject) + size); if (op == NULL) @@ -111,7 +117,7 @@ PyBytes_FromString(const char *str) assert(str != NULL); size = strlen(str); - if (size > PY_SSIZE_T_MAX) { + if (size > PY_SSIZE_T_MAX - sizeof(PyBytesObject)) { PyErr_SetString(PyExc_OverflowError, "byte string is too long"); return NULL; -- cgit v1.2.1