Skip to content

fix: Guard against stack overflow in parse_table_and_joins #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9334,6 +9334,7 @@ impl<'a> Parser<'a> {
}

pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError> {
let _guard = self.recursion_counter.try_decrease()?;
let relation = self.parse_table_factor()?;
// Note that for keywords to be properly handled here, they need to be
// added to `RESERVED_FOR_TABLE_ALIAS`, otherwise they may be parsed as
Expand Down
7 changes: 7 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8838,6 +8838,13 @@ fn parse_deeply_nested_subquery_expr_hits_recursion_limits() {
assert_eq!(res, Err(ParserError::RecursionLimitExceeded));
}

#[test]
fn parse_deeply_nested_update_hits_recursion_limits() {
let sql = format!("UPDATE {}", "(".repeat(1000));
let res = parse_sql_statements(&sql);
assert_eq!(ParserError::RecursionLimitExceeded, res.unwrap_err());
}

#[test]
fn parse_with_recursion_limit() {
let dialect = GenericDialect {};
Expand Down
Loading