Deeply nested constant expressions overflow the parser stack
- Lingua principale
- Rust
- Stelle
- 772
- Fork
- 352
- Merge medio
- 1g 12h
- PR unite (30g)
- 93
Descrizione
A constant expression with many matching parentheses makes `parse_forms` exhaust the thread stack and abort the process. The parser does not return an error. The same path is reachable through `ModuleParser` and `Assembler`.
`FragmentParser::parse_constant_term` calls `parse_constant_expr` for each opening parenthesis without checking the depth.
This test reproduces the abort in `crates/assembly-syntax/src/parser/tests.rs`:
```rust
#[test]
fn rejects_deeply_nested_constant_expression() {
let depth = 10_000;
let source = format!(
"const VALUE = {}1{}\n",
"(".repeat(depth),
")".repeat(depth),
);
let rejected = std::thread::Builder::new()
.stack_size(2 * 1024 * 1024)
.spawn(move || parse_forms(test_source_file(&source)).is_err())
.expect("failed to start parser thread")
.join()
.expect("parser thread panicked");
assert!(rejected, "deep constant expression should return an error");
}
```
The parser should reject excessive constant expression depth before the next recursive call.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.