Commit fd83a823 authored by Zackery Spytz's avatar Zackery Spytz Committed by Serhiy Storchaka

bpo-36504: Fix signed integer overflow in _ctypes.c's PyCArrayType_new(). (GH-12660) (GH-12678)

(cherry picked from commit 487b73ab)
parent a110817c
......@@ -134,6 +134,12 @@ class ArrayTestCase(unittest.TestCase):
t2 = my_int * 1
self.assertIs(t1, t2)
def test_bpo36504_signed_int_overflow(self):
# The overflow check in PyCArrayType_new() could cause signed integer
# overflow.
with self.assertRaises(OverflowError):
c_char * sys.maxsize * 2
@unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
@precisionbigmemtest(size=_2G, memuse=1, dry_run=False)
def test_large_array(self, size):
......
Fix signed integer overflow in _ctypes.c's ``PyCArrayType_new()``.
......@@ -1534,7 +1534,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
itemsize = itemdict->size;
if (length * itemsize < 0) {
if (length > PY_SSIZE_T_MAX / itemsize) {
PyErr_SetString(PyExc_OverflowError,
"array too large");
Py_DECREF(stgdict);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment