-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Building a ctypes.CField
with wrong byte_size
aborts
#132470
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
Comments
|
…e size (pythongh-132470) When creating a ctypes.CField with an incorrect byte_size (e.g., using byte_size=2 for ctypes.c_byte), the code would previously abort due to the failed assertion byte_size == info->size. This commit replaces the assertion with a proper error handling mechanism that raises a ValueError when byte_size does not match the expected type size. This prevents the crash and provides a more informative error message to the us
Adds a test to ensure that creating a ctypes.CField with a byte_size that doesn't match the underlying C type size (e.g., 2 bytes for c_byte) correctly raises a ValueError. This test verifies the fix for pythongh-132470 and prevents future regressions where such mismatches could cause an abort.
Adds a test to ensure that creating a ctypes.CField with a byte_size that doesn't match the underlying C type size (e.g., 2 bytes for c_byte) correctly raises a ValueError. This test verifies the fix for pythongh-132470 and prevents future regressions where such mismatches could cause an abort.
Adds a test to ensure that creating a ctypes.CField with a byte_size that doesn't match the underlying C type size (e.g., 2 bytes for c_byte) correctly raises a ValueError. This test verifies the fix for pythongh-132470 and prevents future regressions where such mismatches could cause an abort.
…ct (#132475) Fix: Prevent crash in ctypes.CField when byte_size does not match type size (gh-132470) When creating a ctypes.CField with an incorrect byte_size (e.g., using `byte_size=2` for `ctypes.c_byte`), the code would previously abort due to the failed assertion `byte_size == info->size`. This commit replaces the assertion with a proper error handling mechanism that raises a `ValueError` when `byte_size` does not match the expected type size. This prevents the crash and provides a more informative error message to the us Co-authored-by: sobolevn <[email protected]>
To set expectations: the With that said, thank you for testing this internal API! And thank you for the fix -- when |
Uh oh!
There was an error while loading. Please reload this page.
Crash report
What happened?
The following code will cause an abort due to
byte_size
not matching the size ofctypes.c_byte
, failing an assertion thatbyte_size == info->size
.Abort message:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a6+ (heads/main:be2d2181e62, Mar 31 2025, 07:30:17) [GCC 11.4.0]
Linked PRs
byte_size
is incorrect #132475The text was updated successfully, but these errors were encountered: