Bound nested SELECT parsing to MAX_PARSER_DEPTH#1
Open
nilox94 wants to merge 1 commit into
Open
Conversation
`enter_depth()` was only checked in `parse_expression_rec`, so deeply nested `FROM (SELECT …)` subqueries could still overflow the parser stack. Route subquery entry points through `parse_nested_select_statement`. Test uses `SELECT *` so the limit is exercised by subquery nesting, not by `parse_expression_rec` on a `SELECT 1` literal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
MAX_PARSER_DEPTHis only checked inparse_expression_rec. NestedSELECTinFROM (...), CTEs,IN (SELECT ...), and scalar subqueries callparse_select_statementwithoutenter_depth(). Subquery nesting has no limit. On deep input the parser stack-overflows instead of returning a parse error.Repro
On
main, with a fresh build (cargo build --bin clickhouse-analyzer):Fix
Add
parse_nested_select_statement(). It wrapsenter_depth()andleave_depth()aroundparse_select_statement(). Use it at subquery entry points:parse_subquery_table_ref(FROM (SELECT …))parse_with_items(CTEs)parse_in_rhs/expr_delimited(IN (SELECT …),(SELECT …))Top-level
SELECTandUNIONRHS are unchanged. They are not nested inside another depth-consuming frame.Adds
bounds_deeply_nested_subqueries: 1001 nestedSELECT * FROM (...)wrappers return a nesting-depth error; 999 parse cleanly.Verify
After this PR, the same query at depth 1001 returns
"Maximum expression nesting depth exceeded"without crashing.cargo test bounds_deeply_nested_subqueries