diff options
author | Andrew Dalke <dalke@dalkescientific.com> | 2006-05-25 18:18:39 +0000 |
---|---|---|
committer | Andrew Dalke <dalke@dalkescientific.com> | 2006-05-25 18:18:39 +0000 |
commit | 598710c7270dc92839be0e1b5608cf7b5b33e7ec (patch) | |
tree | 6ea0466d5b915dc6f9b90ba92261ef02fdcc4518 | |
parent | f344c94c85f5c9028256e1dfd4b837e7aa4171f0 (diff) | |
download | cpython-git-598710c7270dc92839be0e1b5608cf7b5b33e7ec.tar.gz |
Added overflow test for adding two (very) large strings where the
new string is over max Py_ssize_t. I have no way to test it on my
box or any box I have access to. At least it doesn't break anything.
-rw-r--r-- | Objects/stringobject.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 277d4b3287..e74744d369 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1023,7 +1023,7 @@ string_length(PyStringObject *a) static PyObject * string_concat(register PyStringObject *a, register PyObject *bb) { - register size_t size; + register Py_ssize_t size; register PyStringObject *op; if (!PyString_Check(bb)) { #ifdef Py_USING_UNICODE @@ -1047,7 +1047,12 @@ string_concat(register PyStringObject *a, register PyObject *bb) return (PyObject *)a; } size = a->ob_size + b->ob_size; - /* XXX check overflow */ + if (size < 0) { + PyErr_SetString(PyExc_OverflowError, + "strings are too large to concat"); + return NULL; + } + /* Inline PyObject_NewVar */ op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size); if (op == NULL) |