gh-138008: Fix segfaults in _ctypes due to invalid argtypes#138285
gh-138008: Fix segfaults in _ctypes due to invalid argtypes#138285encukou merged 9 commits intopython:mainfrom
Conversation
Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com>
|
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 |
|
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 <204532581+Yzi-Li@users.noreply.github.com>
b60f833 to
45f483c
Compare
Signed-off-by: Nguyen Viet Dung <dung@ekluster.com>
021ee2e to
9c9a65e
Compare
encukou
left a comment
There was a problem hiding this comment.
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.
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.
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 <dung@ekluster.com> Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com> Signed-off-by: Nguyen Viet Dung <dung@ekluster.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com>
|
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 <dung@ekluster.com> Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com> Signed-off-by: Nguyen Viet Dung <dung@ekluster.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com>
…H-138285) (#138746) (cherry picked from commit 1ce0553) Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com> Signed-off-by: Nguyen Viet Dung <dung@ekluster.com> Co-authored-by: Dung Nguyen <dung@ekluster.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com>
This PR adds
_validate_paramflagschecks to thesetattrof argtypes, which is likely the best way to fix this issue without performance regressions.This PR also adds tests for invalid
paramflagsandargtypes.