]> granicus.if.org Git - python/commitdiff
Fixed integer overflow and handled MemoryError in array.buffer_info().
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 23 Jun 2016 21:00:32 +0000 (00:00 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 23 Jun 2016 21:00:32 +0000 (00:00 +0300)
Modules/arraymodule.c

index f14711563c5304d37b0285b9f71bcc125d9ad86d..53507597a2ab2345c9455e2974505c7ff9891e02 100644 (file)
@@ -1067,13 +1067,25 @@ Insert a new item x into the array before position i.");
 static PyObject *
 array_buffer_info(arrayobject *self, PyObject *unused)
 {
-    PyObject* retval = NULL;
+    PyObject *retval = NULL, *v;
+
     retval = PyTuple_New(2);
     if (!retval)
         return NULL;
 
-    PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
-    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_SIZE(self))));
+    v = PyLong_FromVoidPtr(self->ob_item);
+    if (v == NULL) {
+        Py_DECREF(retval);
+        return NULL;
+    }
+    PyTuple_SET_ITEM(retval, 0, v);
+
+    v = PyLong_FromSsize_t(Py_SIZE(self));
+    if (v == NULL) {
+        Py_DECREF(retval);
+        return NULL;
+    }
+    PyTuple_SET_ITEM(retval, 1, v);
 
     return retval;
 }