Skip to content

[3.14] gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031) #135059

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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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
14 changes: 13 additions & 1 deletion Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Python test set -- part 1, grammar.
# This just tests whether the parser accepts them all.

from test.support import check_syntax_error
from test.support import check_syntax_error, skip_wasi_stack_overflow
from test.support import import_helper
import annotationlib
import inspect
Expand Down Expand Up @@ -249,6 +249,18 @@ def test_eof_error(self):
compile(s, "<test>", "exec")
self.assertIn("was never closed", str(cm.exception))

@skip_wasi_stack_overflow()
def test_max_level(self):
# Macro defined in Parser/lexer/state.h
MAXLEVEL = 200

result = eval("(" * MAXLEVEL + ")" * MAXLEVEL)
self.assertEqual(result, ())

with self.assertRaises(SyntaxError) as cm:
eval("(" * (MAXLEVEL + 1) + ")" * (MAXLEVEL + 1))
self.assertStartsWith(str(cm.exception), 'too many nested parentheses')

var_annot_global: int # a global annotated is necessary for test_var_annot


Expand Down
2 changes: 1 addition & 1 deletion Parser/parser.c

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

2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# define MAXSTACK 4000
# endif
#else
# define MAXSTACK 4000
# define MAXSTACK 6000
#endif

"""
Expand Down
Loading