Skip to content

gh-155733: Validate keyword argument keys in operator.methodcaller and functools.partial - #155779

Open
pranavchoudhary-tech wants to merge 3 commits into
python:mainfrom
pranavchoudhary-tech:fix-nonstring-kwargs-155733
Open

gh-155733: Validate keyword argument keys in operator.methodcaller and functools.partial#155779
pranavchoudhary-tech wants to merge 3 commits into
python:mainfrom
pranavchoudhary-tech:fix-nonstring-kwargs-155733

Conversation

@pranavchoudhary-tech

Copy link
Copy Markdown
Contributor

gh-155733: Validate keyword argument keys in operator.methodcaller and functools.partial

Summary

Fixes gh-155733.

Previously, passing non-string keys as **kwargs into operator.methodcaller or functools.partial bypassed kwarg type validation, leading to vectorcall assertion failures (PyUnicode_Check) or segmentation faults in CPython.

This PR adds keyword type checks (PyUnicode_Check) to methodcaller_new, partial_new, and partial_vectorcall, raising TypeError: keywords must be strings cleanly.

@brijkapadia

Copy link
Copy Markdown
Contributor

I think there are some cases that you are missing (like __setstate__). Could you add what is in gh-145960 but not in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault & Debug abort when functools.partial/operator.methodcaller keywords contains non-string keys

2 participants