Skip to content

Commit

Permalink
Further restrict default parser limits
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 624204076
  • Loading branch information
jcking authored and copybara-github committed Apr 12, 2024
1 parent 253e7a4 commit 6059846
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions parser/internal/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace cel_parser_internal {

inline constexpr int kDefaultErrorRecoveryLimit = 30;
inline constexpr int kDefaultMaxRecursionDepth = 50;
inline constexpr int kDefaultErrorRecoveryLimit = 12;
inline constexpr int kDefaultMaxRecursionDepth = 32;
inline constexpr int kExpressionSizeCodepointLimit = 100'000;
inline constexpr int kDefaultErrorRecoveryTokenLookaheadLimit = 512;
inline constexpr bool kDefaultAddMacroCalls = false;
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ void ExprRecursionListener::enterEveryRule(ParserRuleContext* ctx) {
// continue if this were treated as a syntax error and the problem would
// continue to manifest.
if (ctx->getRuleIndex() == CelParser::RuleExpr) {
if (recursion_depth_ >= max_recursion_depth_) {
if (recursion_depth_ > max_recursion_depth_) {
throw ParseCancellationException(
absl::StrFormat("Expression recursion limit exceeded. limit: %d",
max_recursion_depth_));
Expand Down
2 changes: 1 addition & 1 deletion parser/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ std::vector<TestInfo> test_cases = {
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
"]]]]]]",
"", "Expression recursion limit exceeded. limit: 50", "", "", "", false},
"", "Expression recursion limit exceeded. limit: 32", "", "", "", false},
{
// Note, the ANTLR parse stack may recurse much more deeply and permit
// more detailed expressions than the visitor can recurse over in
Expand Down

0 comments on commit 6059846

Please sign in to comment.