mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-03 16:42:54 +00:00
fix: Fix stack overflow in parse_subexpr (#1410)
This commit is contained in:
parent
aa714e3447
commit
4875dadbf5
2 changed files with 8 additions and 1 deletions
|
|
@ -897,12 +897,12 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// Parse a new expression.
|
/// Parse a new expression.
|
||||||
pub fn parse_expr(&mut self) -> Result<Expr, ParserError> {
|
pub fn parse_expr(&mut self) -> Result<Expr, ParserError> {
|
||||||
let _guard = self.recursion_counter.try_decrease()?;
|
|
||||||
self.parse_subexpr(self.dialect.prec_unknown())
|
self.parse_subexpr(self.dialect.prec_unknown())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse tokens until the precedence changes.
|
/// Parse tokens until the precedence changes.
|
||||||
pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError> {
|
pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError> {
|
||||||
|
let _guard = self.recursion_counter.try_decrease()?;
|
||||||
debug!("parsing expr");
|
debug!("parsing expr");
|
||||||
let mut expr = self.parse_prefix()?;
|
let mut expr = self.parse_prefix()?;
|
||||||
debug!("prefix: {:?}", expr);
|
debug!("prefix: {:?}", expr);
|
||||||
|
|
|
||||||
|
|
@ -8980,6 +8980,13 @@ fn parse_deeply_nested_parens_hits_recursion_limits() {
|
||||||
assert_eq!(ParserError::RecursionLimitExceeded, res.unwrap_err());
|
assert_eq!(ParserError::RecursionLimitExceeded, res.unwrap_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_deeply_nested_unary_op_hits_recursion_limits() {
|
||||||
|
let sql = format!("SELECT {}", "+".repeat(1000));
|
||||||
|
let res = parse_sql_statements(&sql);
|
||||||
|
assert_eq!(ParserError::RecursionLimitExceeded, res.unwrap_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_deeply_nested_expr_hits_recursion_limits() {
|
fn parse_deeply_nested_expr_hits_recursion_limits() {
|
||||||
let dialect = GenericDialect {};
|
let dialect = GenericDialect {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue