From 1e9b8f2f8512ca4ede6ca24113a70e13c9a7cf6b Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Mon, 28 Jul 2025 12:32:34 -0400 Subject: [PATCH] gh-131338: Disable computed stack limit checks on non-glibc linux (#134336) Co-authored-by: Kumar Aditya Co-authored-by: Victor Stinner --- .../2025-07-25-22-31-52.gh-issue-131338.zJDCMp.rst | 2 ++ Python/ceval.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-07-25-22-31-52.gh-issue-131338.zJDCMp.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-07-25-22-31-52.gh-issue-131338.zJDCMp.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-25-22-31-52.gh-issue-131338.zJDCMp.rst new file mode 100644 index 000000000000..6c064e8f4a03 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-07-25-22-31-52.gh-issue-131338.zJDCMp.rst @@ -0,0 +1,2 @@ +Disable computed stack limit checks on non-glibc linux platforms to fix +crashes on deep recursion. diff --git a/Python/ceval.c b/Python/ceval.c index 291e753dec0c..9ccd42bdf0a5 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -452,7 +452,11 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate) _tstate->c_stack_soft_limit = _tstate->c_stack_hard_limit + _PyOS_STACK_MARGIN_BYTES; #else uintptr_t here_addr = _Py_get_machine_stack_pointer(); -# if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && !defined(__NetBSD__) +/// XXX musl supports HAVE_PTHRED_GETATTR_NP, but the resulting stack size +/// (on alpine at least) is much smaller than expected and imposes undue limits +/// compared to the old stack size estimation. (We assume musl is not glibc.) +# if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && \ + !defined(__NetBSD__) && (defined(__GLIBC__) || !defined(__linux__)) size_t stack_size, guard_size; void *stack_addr; pthread_attr_t attr; -- 2.47.2