8000 [3.7] bpo-37188: Fix a divide-by-zero in arrays of size-0 objects (GH-13881) by miss-islington · Pull Request #13882 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.7] bpo-37188: Fix a divide-by-zero in arrays of size-0 objects (GH-13881) #13882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lib/ctypes/test/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ class T(Array):
_type_ = c_int
_length_ = 1.87

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.
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,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;
Expand Down
0