[naga wgsl-in] Restore accidentally removed recursion depth check. (#9424)

This commit is contained in:
Jim Blandy authored and GitHub committed 2026-04-14 09:22:29 +02:00
1 parent 7143bbe882
commit fccadd6f07
4 files changed
+20093 -59

No files matched your search

+63 -59
View File
@@ -341,7 +341,7 @@ impl Parser {
F: FnOnce(&mut Self) -> Result<'a, R>,
{
self.recursion_depth += 1;
if self.recursion_depth >= 256 {
if self.recursion_depth >= 200 {
return Err(Box::new(Error::Internal("Parser recursion limit exceeded")));
}
let ret = f(self);
@@ -791,64 +791,68 @@ impl Parser {
lexer: &mut Lexer<'a>,
context: &mut ExpressionContext<'a, '_, '_>,
) -> Result<'a, Handle<ast::Expression<'a>>> {
self.push_rule_span(Rule::GeneralExpr, lexer);
// logical_or_expression
let handle = context.parse_binary_op(
lexer,
|token| match token {
Token::LogicalOperation('|') => Some(crate::BinaryOperator::LogicalOr),
_ => None,
},
// logical_and_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::LogicalOperation('&') => Some(crate::BinaryOperator::LogicalAnd),
_ => None,
},
// inclusive_or_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('|') => Some(crate::BinaryOperator::InclusiveOr),
_ => None,
},
// exclusive_or_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('^') => {
Some(crate::BinaryOperator::ExclusiveOr)
}
_ => None,
},
// and_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('&') => {
Some(crate::BinaryOperator::And)
}
_ => None,
},
|lexer, context| {
self.equality_expression(lexer, context)
},
)
},
)
},
)
},
)
},
)?;
self.pop_rule_span(lexer);
Ok(handle)
self.track_recursion(|this| {
this.push_rule_span(Rule::GeneralExpr, lexer);
// logical_or_expression
let handle = context.parse_binary_op(
lexer,
|token| match token {
Token::LogicalOperation('|') => Some(crate::BinaryOperator::LogicalOr),
_ => None,
},
// logical_and_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::LogicalOperation('&') => Some(crate::BinaryOperator::LogicalAnd),
_ => None,
},
// inclusive_or_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('|') => {
Some(crate::BinaryOperator::InclusiveOr)
}
_ => None,
},
// exclusive_or_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('^') => {
Some(crate::BinaryOperator::ExclusiveOr)
}
_ => None,
},
// and_expression
|lexer, context| {
context.parse_binary_op(
lexer,
|token| match token {
Token::Operation('&') => {
Some(crate::BinaryOperator::And)
}
_ => None,
},
|lexer, context| {
this.equality_expression(lexer, context)
},
)
},
)
},
)
},
)
},
)?;
this.pop_rule_span(lexer);
Ok(handle)
})
}
fn optionally_typed_ident<'a>(
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+22
View File
@@ -984,6 +984,28 @@ fn matrix_constructor_inferred() {
);
}
#[test]
fn recursion_depth_expression() {
check(
include_str!("deep-expression.wgsl"),
r#"error: internal WGSL front end error
= note: Parser recursion limit exceeded
"#,
);
}
#[test]
fn recursion_depth_template() {
check(
include_str!("deep-template.wgsl"),
r#"error: internal WGSL front end error
= note: Parser recursion limit exceeded
"#,
);
}
/// Check the result of validating a WGSL program against a pattern.
///
/// Unless you are generating code programmatically, the