From 5dadae5dfecd28e52fb6a6c87f7903590ec39a6d Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 7 Mar 2025 21:50:31 +0000 Subject: [PATCH] gh-130396: Fix thread sanitizer crashes on stack overflow tests Thread sanitizer will often crash if a test uses more than half the stack. --- Python/ceval.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 0a3b30513733bd..1ba9e7996a6c3c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -373,7 +373,12 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate) if (err == 0) { uintptr_t base = ((uintptr_t)stack_addr) + guard_size; _tstate->c_stack_top = base + stack_size; +#ifdef _Py_THREAD_SANITIZER + // Thread sanitizer crashes if we use a bit more than half the stack. + _tstate->c_stack_soft_limit = base + (stack_size / 2); +#else _tstate->c_stack_soft_limit = base + PYOS_STACK_MARGIN_BYTES * 2; +#endif _tstate->c_stack_hard_limit = base + PYOS_STACK_MARGIN_BYTES; assert(_tstate->c_stack_soft_limit < here_addr); assert(here_addr < _tstate->c_stack_top);