]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130396: Fix thread sanitizer crashes on stack overflow tests (gh-130966)
authorSam Gross <colesbury@gmail.com>
Tue, 11 Mar 2025 14:33:23 +0000 (10:33 -0400)
committerGitHub <noreply@github.com>
Tue, 11 Mar 2025 14:33:23 +0000 (10:33 -0400)
Thread sanitizer will often crash if a test uses more than half the
stack.

Python/ceval.c

index a702d296e2247afe2b65a8ed8d045b9d229ca691..f9089d7f11f280f46d8ebedf78189ed750b96000 100644 (file)
@@ -392,7 +392,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);