-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-138008: Fix segfaults in _ctypes due to invalid argtypes #138285
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
Conversation
Signed-off-by: Nguyen Viet Dung <[email protected]>
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Signed-off-by: Nguyen Viet Dung <[email protected]>
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Misc/NEWS.d/next/Library/2025-08-31-09-06-49.gh-issue-138008.heOvsU.rst
Outdated
Show resolved
Hide resolved
…eOvsU.rst Co-authored-by: Yongzi Li <[email protected]>
b60f833
to
45f483c
Compare
Signed-off-by: Nguyen Viet Dung <[email protected]>
021ee2e
to
9c9a65e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I have some suggestions.
Could you also test that with paramflag 2 (“output argument”), the argtype must be a pointer?
I have made the requested changes; please review again. |
16c5fbe
to
adf387f
Compare
Modules/_ctypes/_ctypes.c
Outdated
return 0; | ||
} | ||
argtypes = info->argtypes; | ||
if (argtypes == NULL || argtypes == Py_None) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move the Py_None
check to _ctypes_CFuncPtr_argtypes_set_impl
? It would be nice to have this closer to the “user”, so the internals only need to consider NULL
as special.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the Py_None
check since it's already handled by _ctypes_CFuncPtr_argtypes_set_impl
. The argtypes
parameter will either be NULL or a non-None value.
Thanks @magnified103 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Thanks @magnified103 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Sorry, @magnified103 and @encukou, I could not cleanly backport this to
|
Thank you for the report and fix! |
…thonGH-138285) (cherry picked from commit 1ce0553) Co-authored-by: Dung Nguyen <[email protected]> Signed-off-by: Nguyen Viet Dung <[email protected]> Signed-off-by: Nguyen Viet Dung <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <[email protected]>
GH-138742 is a backport of this pull request to the 3.14 branch. |
GH-138745 is a backport of this pull request to the 3.13 branch. |
GH-138746 is a backport of this pull request to the 3.13 branch. |
…pes (pythonGH-138285) (cherry picked from commit 1ce0553) Co-authored-by: Dung Nguyen <[email protected]> Signed-off-by: Nguyen Viet Dung <[email protected]> Signed-off-by: Nguyen Viet Dung <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <[email protected]>
…H-138285) (#138746) (cherry picked from commit 1ce0553) Signed-off-by: Nguyen Viet Dung <[email protected]> Signed-off-by: Nguyen Viet Dung <[email protected]> Co-authored-by: Dung Nguyen <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <[email protected]>
…H-138285) (GH-138742) (cherry picked from commit 1ce0553) Signed-off-by: Nguyen Viet Dung <[email protected]> Co-authored-by: Yongzi Li <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
This PR adds
_validate_paramflags
checks to thesetattr
of argtypes, which is likely the best way to fix this issue without performance regressions.This PR also adds tests for invalid
paramflags
andargtypes
.