Kaydet (Commit) 0690c79c authored tarafından Eric Wieser's avatar Eric Wieser Kaydeden (comit) Stefan Krah

bpo-37188: Fix a divide-by-zero in arrays of size-0 objects (#13881)

üst 554450fb
......@@ -208,6 +208,21 @@ class ArrayTestCase(unittest.TestCase):
_type_ = c_int
_length_ = 0
def test_empty_element_struct(self):
class EmptyStruct(Structure):
_fields_ = []
obj = (EmptyStruct * 2)() # bpo37188: Floating point exception
assert sizeof(obj) == 0
def test_empty_element_array(self):
class EmptyArray(Array):
_type_ = c_int
_length_ = 0
obj = (EmptyArray * 2)() # bpo37188: Floating point exception
assert sizeof(obj) == 0
def test_bpo36504_signed_int_overflow(self):
# The overflow check in PyCArrayType_new() could cause signed integer
# overflow.
......
......@@ -1518,7 +1518,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
itemsize = itemdict->size;
if (length > PY_SSIZE_T_MAX / itemsize) {
if (itemsize != 0 && length > PY_SSIZE_T_MAX / itemsize) {
PyErr_SetString(PyExc_OverflowError,
"array too large");
goto error;
......
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