Skip to content

Commit b07a267

Browse files
gh-137883: Check the recursion limit for specialized keyword argument calls (GH-137887)
1 parent bb75dec commit b07a267

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_call.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,14 @@ def c_py_recurse(m):
10741074
with self.assertRaises(RecursionError):
10751075
c_py_recurse(100_000)
10761076

1077+
def test_recursion_with_kwargs(self):
1078+
# GH-137883: The interpreter forgot to check the recursion limit when
1079+
# calling with keywords.
1080+
def recurse_kw(a=0):
1081+
recurse_kw(a=0)
1082+
with self.assertRaises(RecursionError):
1083+
recurse_kw()
1084+
10771085

10781086
class TestFunctionWithManyArgs(unittest.TestCase):
10791087
def test_function_with_many_args(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix runaway recursion when calling a function with keyword arguments.

Python/bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,6 +4721,7 @@ dummy_func(
47214721
unused/1 + // Skip over the counter
47224722
_CHECK_PEP_523 +
47234723
_CHECK_FUNCTION_VERSION_KW +
4724+
_CHECK_RECURSION_REMAINING +
47244725
_PY_FRAME_KW +
47254726
_SAVE_RETURN_OFFSET +
47264727
_PUSH_FRAME;

Python/generated_cases.c.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)