Skip to content

Commit 1962567

Browse files
Fix rejection when non-bitfield fields are larger than 2^16 bytes
1 parent 9d6366b commit 1962567

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Modules/_ctypes/cfield.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,21 @@ PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
110110
goto error;
111111
}
112112

113-
Py_ssize_t bit_size = NUM_BITS(size);
114-
if (bit_size) {
113+
if (bit_size_obj != Py_None) {
114+
115+
Py_ssize_t bit_size;
116+
117+
if (PyLong_Check(bit_size_obj)) {
118+
bit_size = PyLong_AsSsize_t(bit_size_obj);
119+
} else {
120+
PyErr_Format(
121+
PyExc_ValueError,
122+
"bit size of field %R must be an integer size for bit fields",
123+
self->name
124+
);
125+
goto error;
126+
}
127+
115128
assert(bit_size > 0);
116129
assert(bit_size <= info->size * 8);
117130
switch(info->ffi_type_pointer.type) {

0 commit comments

Comments
 (0)