]> granicus.if.org Git - python/commitdiff
Added overflow test for adding two (very) large strings where the
authorAndrew Dalke <dalke@dalkescientific.com>
Thu, 25 May 2006 18:18:39 +0000 (18:18 +0000)
committerAndrew Dalke <dalke@dalkescientific.com>
Thu, 25 May 2006 18:18:39 +0000 (18:18 +0000)
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.

Objects/stringobject.c

index 277d4b3287e38c0931410a0287124c216d2bc308..e74744d369028d40adb8d229b548bc1ef211a352 100644 (file)
@@ -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)