gh-155452: Prevent recursion crash in dir() - #155453
Conversation
skirpichev
left a comment
There was a problem hiding this comment.
Apparently, this fails on WASI/emscripten.
I think you should create a separate test and filter it out with skip_wasi_stack_overflow/skip_emscripten_stack_overflow decorators.
| Py_DECREF(bases); | ||
| return -1; | ||
| } | ||
| else { |
There was a problem hiding this comment.
You can reduce patch, leaving "else" branch. Just add _Py_EnterRecursiveCall/_Py_LeaveRecursiveCall calls.
ZeroIntensity
left a comment
There was a problem hiding this comment.
I am extremely opposed to accepting changes of this nature; see #155102 (comment) and #155452 (comment).
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
gh-155452: Prevent recursion crash in
dir()when__bases__is cyclic.Summary
dir()could cause a native stack overflow when an object's__class__provided a cyclic
__bases__attribute.merge_class_dict()recursively traverses__bases__without a recursionguard. This change protects that recursion with
_Py_EnterRecursiveCall()and
_Py_LeaveRecursiveCall(), matching the existing protection inabstract_issubclass().Changes
pycore_ceval.hinclude.__bases__traversal inmerge_class_dict().__bases__graph.Testing
Before the fix, the reproducer resulted in:
After the fix, it raises:
Targeted regression test:
Closes issue gh-155452