parser: add missing level guard in if let

Resolves <https://issues.oss-fuzz.com/issues/393401467>
This commit is contained in:
René Kijewski 2025-02-01 05:11:32 +01:00
parent 9b0ed3c952
commit e1d61276e9
5 changed files with 9746 additions and 1 deletions

View File

@ -3,9 +3,10 @@ group_imports = "StdExternalCrate"
imports_granularity = "Module"
newline_style = "Unix"
normalize_comments = true
overflow_delimited_expr = true
style_edition = "2024"
unstable_features = true
use_field_init_shorthand = true
style_edition = "2024"
ignore = [
"testing/tests/hello.rs",

1
rinja/.rustfmt.toml Symbolic link
View File

@ -0,0 +1 @@
../.rustfmt.toml

View File

@ -426,6 +426,7 @@ impl<'a> CondTest<'a> {
let mut expr = Expr::parse(i, s.level, false)?;
if let Expr::BinOp(_, _, ref mut right) = expr.inner {
if matches!(right.inner, Expr::Var("set" | "let")) {
let _level_guard = s.level.nest(i)?;
*i = right.span.as_suffix_of(start).unwrap();
let start_span = Span::from(*i);
let new_right = Self::parse_cond(i, s)?;

View File

@ -1288,3 +1288,14 @@ fn test_generics_parsing() {
)
.unwrap();
}
#[test]
fn fuzzed_deeply_tested_if_let() {
let src = include_str!("../tests/fuzzed-deeply-tested-if-let.txt");
let syntax = Syntax::default();
let err = Ast::from_str(src, None, &syntax).unwrap_err();
assert_eq!(
err.to_string().lines().next(),
Some("your template code is too deeply nested, or the last expression is too complex"),
);
}

File diff suppressed because it is too large Load Diff