Skip to content

gh-137883: Check the recursion limit for specialized keyword argument calls #137887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,14 @@ def c_py_recurse(m):
with self.assertRaises(RecursionError):
c_py_recurse(100_000)

def test_recursion_with_kwargs(self):
# GH-137883: The interpreter forgot to check the recursion limit when
# calling with keywords.
def recurse_kw(a=0):
recurse_kw(a=0)
with self.assertRaises(RecursionError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be wrapped with with support.infinite_recursion():.

recurse_kw()


class TestFunctionWithManyArgs(unittest.TestCase):
def test_function_with_many_args(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix runaway recursion when calling a function with keyword arguments.
1 change: 1 addition & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4721,6 +4721,7 @@ dummy_func(
unused/1 + // Skip over the counter
_CHECK_PEP_523 +
_CHECK_FUNCTION_VERSION_KW +
_CHECK_RECURSION_REMAINING +
_PY_FRAME_KW +
_SAVE_RETURN_OFFSET +
_PUSH_FRAME;
Expand Down
8 changes: 8 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading