Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbb7b9d

Browse files
committed
Fixed problem with missing PyInt_CheckExact() macro in _ctypes.c
1 parent 50ab942 commit dbb7b9d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,22 +954,27 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
954954
StgDictObject *itemdict;
955955
PyObject *proto;
956956
PyObject *typedict;
957-
int length;
958-
957+
long length;
958+
int overflow;
959959
Py_ssize_t itemsize, itemalign;
960960

961961
typedict = PyTuple_GetItem(args, 2);
962962
if (!typedict)
963963
return NULL;
964964

965965
proto = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
966-
if (!proto || !PyInt_CheckExact(proto)) {
966+
if (!proto || !PyLong_Check(proto)) {
967967
PyErr_SetString(PyExc_AttributeError,
968968
"class must define a '_length_' attribute, "
969969
"which must be a positive integer");
970970
return NULL;
971971
}
972-
length = PyLong_AS_LONG(proto);
972+
length = PyLong_AsLongAndOverflow(proto, &overflow);
973+
if (overflow) {
974+
PyErr_SetString(PyExc_OverflowError,
975+
"The '_length_' attribute is too large");
976+
return NULL;
977+
}
973978

974979
proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
975980
if (!proto) {

0 commit comments

Comments
 (0)