Skip to content

Fix test_from_rnc_input_bad_1 crash on Python 3.11, 3.12 - #132

Open
andersk wants to merge 2 commits into
abelcheung:mainfrom
andersk:test_from_rnc_input_bad_1
Open

andersk wants to merge 2 commits into
abelcheung:mainfrom
andersk:test_from_rnc_input_bad_1

Conversation

@andersk

@andersk andersk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Our all_instances_except_of_type strategy sometimes yields class objects like str. When test_from_rnc_input_bad_1 passes str to RelaxNG.from_rnc_string, rnc2rng makes an unbound str.splitlines() call with no arguments. That should just throw TypeError that’s caught by the test. But in CPython 3.11 and 3.12, the specialized CALL instructions for METH_FASTCALL methods like str.splitlines forgot to check for a missing self argument, so such a call may read past the end of the stack and segfault:

This seems to be the root cause for the uninvestigated Python 3.11/3.12 crash that motivated disabling the test in commit 8ecf09c. Prevent such crashes by excluding class objects from this strategy altogether on affected versions.

Our `all_instances_except_of_type` strategy sometimes yields class
objects like `str`.  When `test_from_rnc_input_bad_1` passes `str` to
`RelaxNG.from_rnc_string`, rnc2rng makes an unbound `str.splitlines()`
call with no arguments.  That should just throw `TypeError` that’s
caught by the test.  But in CPython 3.11 and 3.12, the specialized
`CALL` instructions for `METH_FASTCALL` methods like `str.splitlines`
forgot to check for a missing `self` argument, so such a call may read
past the end of the stack and segfault:

python/cpython#131998

This seems to be the root cause for the uninvestigated Python
3.11/3.12 crash that motivated disabling the test in commit 8ecf09c.
Prevent such crashes by excluding class objects from this strategy
altogether on affected versions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@andersk
andersk force-pushed the test_from_rnc_input_bad_1 branch from 58f1d2e to 1f6447e Compare September 25, 2026 23:46
This test was skipped in 8ecf09c due to an uninvestigated crash on
Python 3.11 and 3.12, and later marked as an expected failure on
GitHub Actions instead.  The crash was CPython gh-131998, which the
previous commit avoids by no longer passing class objects to the code
under test.  An expected failure marker couldn't have caught a
segfault anyway, and would hide genuine failures of this test on
GitHub.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@andersk
andersk force-pushed the test_from_rnc_input_bad_1 branch from 1f6447e to 9105a68 Compare September 25, 2026 23:47
@abelcheung

Copy link
Copy Markdown
Owner

Wow, million thanks for tracking it down, I always lacked the motivation to delve into rabbit hole myself. Just one small question though, does the problem only happens within GitHub actions?

@andersk

andersk commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

No. It’s nondeterministic so there may be environmental factors that make it more or less likely, but I was able to reproduce the crash several times while running the tests locally.

This branch has not been deployed

No deployments
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.

2 participants