Skip to content
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

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

Open
jjbayer opened this issue Sep 26, 2023 · 1 comment
Open

Comments

@jjbayer
Copy link
Contributor

jjbayer commented Sep 26, 2023

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

@alamb
Copy link
Collaborator

alamb commented Oct 2, 2023

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

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

@alamb alamb changed the title Stack overflow in Statement::to_string Stack overflow in Statement::to_string for deeply nested expresions Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants