From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 3 Jun 2025 12:23:06 +0000 (+0200) Subject: [3.14] gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031) (#135059) X-Git-Tag: v3.14.0b3~101 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89df01bd2718fb43f2dd1f884381cb9f2a7cf289;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031) (#135059) gh-135028: Increase parser MAXSTACK for nested parenthesis (GH-135031) (cherry picked from commit 6e80f11eb5eba360334b4ace105eb7d73394baf7) Co-authored-by: Victor Stinner --- diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index c39565144bf7..7f5d48b9c63a 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -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 @@ -249,6 +249,18 @@ the \'lazy\' dog.\n\ compile(s, "", "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 diff --git a/Parser/parser.c b/Parser/parser.c index dc55e391d292..5755f16a65c5 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -14,7 +14,7 @@ # define MAXSTACK 4000 # endif #else -# define MAXSTACK 4000 +# define MAXSTACK 6000 #endif static const int n_keyword_lists = 9; static KeywordToken *reserved_keywords[] = { diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 2be85a163b40..09c5651f24a3 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -44,7 +44,7 @@ EXTENSION_PREFIX = """\ # define MAXSTACK 4000 # endif #else -# define MAXSTACK 4000 +# define MAXSTACK 6000 #endif """