Skip to content

Commit 14fbb92

Browse files
cdlearycopybara-github
authored andcommitted
[DSLX:frontend] Bump expression nesting depth in Parser::ParseTermLhs
This is one of the "most interior" production rules in the recursive descent grammar -- previously we were bumping the counter in Parser::ParseExpression which is more "outer" -- this should help prevent more over-recursion issues in coverage-guided fuzzing. PiperOrigin-RevId: 612920050
1 parent 3f1b2ad commit 14fbb92

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

xls/dslx/frontend/parser.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,14 @@ absl::StatusOr<Expr*> Parser::ParseTermLhsParenthesized(
15531553
absl::StatusOr<Expr*> Parser::ParseTermLhs(Bindings& outer_bindings,
15541554
ExprRestrictions restrictions) {
15551555
XLS_ASSIGN_OR_RETURN(const Token* peek, PeekToken());
1556+
1557+
if (++approximate_expression_depth_ >= kApproximateExpressionDepthLimit) {
1558+
return ParseErrorStatus(peek->span(),
1559+
"Expression is too deeply nested, please break "
1560+
"into multiple statements");
1561+
}
1562+
auto bump_down = absl::Cleanup([this] { approximate_expression_depth_--; });
1563+
15561564
const Pos start_pos = peek->span().start();
15571565
XLS_VLOG(5) << "ParseTerm @ " << start_pos << " peek: `" << peek->ToString()
15581566
<< "` restrictions: " << ExprRestrictionsToString(restrictions);

0 commit comments

Comments
 (0)