Skip to content

Avoid non-string binding crashes in BoundFunctionWrapper calls - #369

Closed
edsonsims wants to merge 1 commit into
GrahamDumpleton:developfrom
edsonsims:fix/non-string-bound-wrapper-binding
Closed

edsonsims wants to merge 1 commit into
GrahamDumpleton:developfrom
edsonsims:fix/non-string-bound-wrapper-binding

Conversation

@edsonsims

Copy link
Copy Markdown

Fixes #368.

I guard the Unicode-only comparison in BoundFunctionWrapper call dispatch with PyUnicode_Check. Ordinary non-string values then use the existing fallback path, as they do in the pure Python implementation, while normal string bindings and disabled wrappers keep their current behavior.

The regression tests cover free functions and bound class methods with ordinary non-string bindings, unknown string bindings, and disabled wrappers. The change note credits the original report.

Validation on macOS arm64:

  • The reported reproducer exits with SIGSEGV on the original C extension and returns ok with the original pure Python implementation.
  • Focused candidate tests pass with both implementations: 4 tests / 16 subtests each.
  • just test passes all 24 matrix cells: Python 3.10–3.15, including 3.14t/3.15t, with pure Python, C enabled, and C disabled at runtime. The 3.15 interpreters tested were 3.15.0rc2.
  • just test-mypy passes all six configured target versions with the pinned mypy 1.20.1.

@GrahamDumpleton

Copy link
Copy Markdown
Owner

Thanks for the PR. I've superseded it with #371, which has now been merged. Your fix for BoundFunctionWrapper.__call__() was correct, but the same unsafe comparison of the binding was made in several other places too: calling an unbound FunctionWrapper, and binding a wrapper through __get__(). Those could still be reached, for example by applying a decorator to a wrapper with a non-string binding. Rather than guarding each call to PyUnicode_CompareWithASCIIString(), #371 switches all of them to an existing helper that compares against the interned binding names and rejects anything that isn't a string. You're credited for the PR in the change note.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BoundFunctionWrapper segfaults when binding is not a string

2 participants