Limit maximum number of references in generics to prevent syn stack overflow

This commit is contained in:
Guillaume Gomez 2025-10-16 21:59:25 +02:00 committed by René Kijewski
parent 7fe8788f82
commit 04cf06beb4
4 changed files with 18 additions and 0 deletions

View File

@ -1289,6 +1289,10 @@ impl<'a: 'l, 'l> TyGenerics<'a> {
let p = ws((repeat(0.., ws('&')), path, opt(Self::args)));
let ((refs, path, args), span) = p.with_span().parse_next(i)?;
let max_refs = 20;
if refs > max_refs {
return cut_error!(format!("too many references (> {max_refs})"), span);
}
if let [name] = path.as_slice() {
if matches!(**name, "super" | "self" | "crate") {

View File

@ -0,0 +1,7 @@
use askama::Template;
#[derive(Template)]
#[template(source = "{{J::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&e>()}}", ext = "html")]
struct X;
fn main() {}

View File

@ -0,0 +1,7 @@
error: too many references (> 20)
--> <source attribute>:1:6
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&e>()}}"
--> tests/ui/references.rs:4:21
|
4 | #[template(source = "{{J::<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&e>()}}", ext = "html")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^