Skip to content

Stack overflow in Statement::to_string for deeply nested expresions #984

Closed

Description

@jjbayer

It seems that Statement::to_string overflows for deep expressions even if the default recursion limit is able to parse the expression without error:

#[test]
fn render_overflow() {
    let expr = "SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1";
    let statements = sqlparser::parser::Parser::parse_sql(&GenericDialect {}, expr).unwrap();
    println!("Was able to parse");
    assert_eq!(&statements[0].to_string(), expr);
}

Outputs

Was able to parse

thread 'normalize::span::description::sql::parser::render_overflow' has overflowed its stack
fatal runtime error: stack overflow

Version: 0.37.0

Activity

  1. alamb commented on Oct 2, 2023

    @alamb
    Contributor

    Thank you @jjbayer -- this would indeed be nice to fix.

    I do suspect this would be less likely to happen in release builds

  2. changed the title [-]Stack overflow in `Statement::to_string`[/-] [+]Stack overflow in `Statement::to_string` for deeply nested expresions[/+] on Oct 2, 2023
  3. blaginin commented on Nov 14, 2024

    @blaginin
    Member

    @2010YOUY01 made a great point about stack overflow today!

    @alamb, are you OK if I bring #[recursive] here as well? cc @peter-toth

  4. peter-toth commented on Nov 14, 2024

    @peter-toth

    @2010YOUY01 made a great point about stack overflow today!

    @alamb, are you OK if I bring #[recursive] here as well? cc @peter-toth

    @blaginin, apache/datafusion#9375 (comment) / apache/datafusion#13376 (comment) (Issue 1) was also an sqlparser issue, that probably can be fixed with #[recursive]. I wonder if you could fix that as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions