From: Serhiy Storchaka Date: Thu, 23 Jun 2016 21:00:32 +0000 (+0300) Subject: Fixed integer overflow and handled MemoryError in array.buffer_info(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cc5a2b263b3783adf687f41e6f77b840a39032e;p=python Fixed integer overflow and handled MemoryError in array.buffer_info(). --- diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index f14711563c..53507597a2 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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; }