Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT a FROM (SELECT a IN (SELECT a FROM (SELECT a FROM t) AS e) AS a FROM t) AS d;
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17683,6 +17683,7 @@ impl<'a> Parser<'a> {
Ok(TableWithJoins { relation, joins })
}

#[cfg_attr(feature = "recursive-protection", recursive::recursive)]
fn parse_joins(&mut self) -> Result<Vec<Join>, ParserError> {
let mut joins = vec![];
loop {
Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23830,3 +23830,21 @@ fn parse_try_cast_shortcut() {
dialects.one_statement_parses_to("SELECT ? ::INT", "SELECT ?::INT");
dialects.verified_stmt("SELECT v:items[0].price?::DECIMAL(10,2)");
}

#[test]
#[cfg(feature = "recursive-protection")]
fn nested_derived_tables_do_not_overflow_the_stack() {
let sql = (0..6).fold("SELECT a FROM t".to_owned(), |inner, _| {
format!("SELECT a FROM (SELECT a IN (SELECT a FROM ({inner}) AS e) AS a FROM t) AS d")
});
// The remaining stack at each check depends on the thread's stack size.
for stack_kib in (256..=2048).step_by(4) {
let sql = sql.clone();
std::thread::Builder::new()
.stack_size(stack_kib * 1024)
.spawn(move || Parser::parse_sql(&GenericDialect {}, &sql).unwrap())
.unwrap()
.join()
.unwrap();
}
}
Loading