You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Excessive stack use in _PyModule_IsPossiblyShadowing #158918
While debugging a test failure of ft_utils.tests.test_localwrapper.TestLocalWrapperAttributes.test_recursion_guard I noticed _PyModule_IsPossiblyShadowing stack-allocating not one, but twoMAXPATHLEN-sized wchar_t buffers. (The second buffer is only used when sys.path[0] is "", which should be pretty rare given that it's normalized very early on in Python's startup.) The two buffers push the function's stack size past 32k, which means a call to it while producing a RecursionError can cause a stack overrun.
I haven't been able to reproduce such a case because of other protections involved, but when _PyModule_IsPossiblyShadowing is inlined into _Py_module_getattro (via _Py_module_getattro_impl), any attribute lookup ends up using 32k+ stack and that is a much bigger deal. Arguably this is a case of bad inlining decisions, but since it's fairly trivial and equally arguably more efficient to heap allocate the buffers here (given that the second allocation is very unlikely to be necessary), I think we should fix _PyModule_IsPossiblyShadowing. I have a PR for this.
Activity
gh-158918: Reduce C stack usage of `_PyModule_IsPossiblyShadowing`. (G…
[3.15] gh-158918: Reduce C stack usage of `_PyModule_IsPossiblyShadow…
[3.14] gh-158918: Reduce C stack usage of `_PyModule_IsPossiblyShadow…