Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-126937: ctypes: fix TypeError when a field's size is >65535 bytes #126938

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 20 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Next Next commit
Fix rejection when non-bitfield fields are larger than 2^16 bytes
  • Loading branch information
Melissa0x1f992 committed Nov 17, 2024
commit 1962567aac71c16604a405c060b9a11ec6a82646
17 changes: 15 additions & 2 deletions 17 Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,21 @@ PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
goto error;
}

Py_ssize_t bit_size = NUM_BITS(size);
if (bit_size) {
if (bit_size_obj != Py_None) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a newline

Suggested change

Py_ssize_t bit_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint is complaining about this. I'm assuming this just needs to get moved to before the if


if (PyLong_Check(bit_size_obj)) {
bit_size = PyLong_AsSsize_t(bit_size_obj);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyLong_AsSsize_t can fail, you need to check for < 0 and then goto error.

} else {
PyErr_Format(
PyExc_ValueError,
"bit size of field %R must be an integer size for bit fields",
self->name
);
goto error;
}

terryjreedy marked this conversation as resolved.
Show resolved Hide resolved
assert(bit_size > 0);
assert(bit_size <= info->size * 8);
switch(info->ffi_type_pointer.type) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.