Skip to content

Commit 0cc5a2b

Browse files
Fixed integer overflow and handled MemoryError in array.buffer_info().
1 parent aaa4baf commit 0cc5a2b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎Modules/arraymodule.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,25 @@ Insert a new item x into the array before position i.");
10671067
static PyObject *
10681068
array_buffer_info(arrayobject *self, PyObject *unused)
10691069
{
1070-
PyObject* retval = NULL;
1070+
PyObject *retval = NULL, *v;
1071+
10711072
retval = PyTuple_New(2);
10721073
if (!retval)
10731074
return NULL;
10741075

1075-
PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
1076-
PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_SIZE(self))));
1076+
v = PyLong_FromVoidPtr(self->ob_item);
1077+
if (v == NULL) {
1078+
Py_DECREF(retval);
1079+
return NULL;
1080+
}
1081+
PyTuple_SET_ITEM(retval, 0, v);
1082+
1083+
v = PyLong_FromSsize_t(Py_SIZE(self));
1084+
if (v == NULL) {
1085+
Py_DECREF(retval);
1086+
return NULL;
1087+
}
1088+
PyTuple_SET_ITEM(retval, 1, v);
10771089

10781090
return retval;
10791091
}

0 commit comments

Comments
 (0)