From d2af609de1c52b2d96cdba9872736e2fe9178222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Thu, 3 Dec 2026 23:27:50 +0100 Subject: [PATCH 1/3] up --- Lib/test/crashers/trace_at_recursion_limit.py | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 Lib/test/crashers/trace_at_recursion_limit.py diff --git a/Lib/test/crashers/trace_at_recursion_limit.py b/Lib/test/crashers/trace_at_recursion_limit.py deleted file mode 100644 index acd863f5509c49b..000000000000000 --- a/Lib/test/crashers/trace_at_recursion_limit.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -From http://bugs.python.org/issue6717 - -A misbehaving trace hook can trigger a segfault by exceeding the recursion -limit. -""" -import sys - - -def x(): - pass - -def g(*args): - if True: # change to True to crash interpreter - try: - x() - except: - pass - return g - -def f(): - print(sys.getrecursionlimit()) - f() - -sys.settrace(g) - -f() From 234eb353351616fde1a93fe5d8dbe27eeaffba30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Thu, 3 Dec 2026 23:38:41 +0100 Subject: [PATCH 2/3] test --- Lib/test/test_sys_settrace.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index a5e7bbbfad5ffca..0fa23797f3bdd4a 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -3047,6 +3047,30 @@ def setUp(self): self.addCleanup(sys.settrace, sys.gettrace()) sys.settrace(None) + def test_trace_at_recursion_limit(self): + caught_in_trace = False + + def helper(): + pass + + def trace(frame, event, arg): + nonlocal caught_in_trace + try: + helper() + except RecursionError: + caught_in_trace = True + return trace + + def recurse(n): + if n: + recurse(n - 1) + + with support.infinite_recursion(25): + with self.assertRaises(RecursionError): + sys.settrace(trace) + recurse(40) + self.assertTrue(caught_in_trace) + def test_reentrancy(self): def foo(*args): ... From 623c470199b1d4d39475d3c3f089f6cdd7a2fd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Thu, 3 Dec 2026 23:39:48 +0100 Subject: [PATCH 3/3] simpler --- Lib/test/test_sys_settrace.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 0fa23797f3bdd4a..6ba9fa355f75b5a 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -3048,27 +3048,23 @@ def setUp(self): sys.settrace(None) def test_trace_at_recursion_limit(self): - caught_in_trace = False + def recurse(n): + if n: + recurse(n - 1) - def helper(): - pass + caught_in_trace = False def trace(frame, event, arg): nonlocal caught_in_trace try: - helper() + recurse(0) except RecursionError: caught_in_trace = True return trace - def recurse(n): - if n: - recurse(n - 1) - - with support.infinite_recursion(25): - with self.assertRaises(RecursionError): - sys.settrace(trace) - recurse(40) + with support.infinite_recursion(25), self.assertRaises(RecursionError): + sys.settrace(trace) + recurse(40) self.assertTrue(caught_in_trace) def test_reentrancy(self):