diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index d7d173cb98e..e3c43c0ed44 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -959,6 +959,9 @@ RefPtr Parser::parse_list_expression() RefPtr Parser::parse_expression() { auto rule_start = push_start(); + if (m_rule_start_offsets.size() > max_allowed_nested_rule_depth) + return create(String::formatted("Expression nested too deep (max allowed is {})", max_allowed_nested_rule_depth)); + auto starting_char = peek(); auto read_concat = [&](auto&& expr) -> NonnullRefPtr { diff --git a/Shell/Parser.h b/Shell/Parser.h index cf5ee4eb6de..5fe34308b56 100644 --- a/Shell/Parser.h +++ b/Shell/Parser.h @@ -51,6 +51,7 @@ public: SavedOffset save_offset() const; private: + constexpr static size_t max_allowed_nested_rule_depth = 2048; RefPtr parse_toplevel(); RefPtr parse_sequence(); RefPtr parse_function_decl();