Skip to content

Commit

Permalink
Merge pull request ClickHouse#55749 from ClickHouse/backport/23.9/55602
Browse files Browse the repository at this point in the history
Backport ClickHouse#55602 to 23.9: Fix crash in QueryNormalizer with cyclic aliases
  • Loading branch information
vdimir committed Oct 18, 2023
2 parents dbc5fb8 + a9dc274 commit 6f8349c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Interpreters/QueryNormalizer.cpp
Expand Up @@ -68,6 +68,10 @@ class RestoreAliasOnExitScope

void QueryNormalizer::visit(ASTIdentifier & node, ASTPtr & ast, Data & data)
{
/// We do handle cycles via tracking current_asts
/// but in case of bug in that tricky logic we need to prevent stack overflow
checkStackSize();

auto & current_asts = data.current_asts;
String & current_alias = data.current_alias;

Expand Down
@@ -0,0 +1 @@
1 2 3
17 changes: 17 additions & 0 deletions tests/queries/0_stateless/02896_cyclic_aliases_crash.sql
@@ -0,0 +1,17 @@

SET max_ast_depth = 10_000_000;

SELECT
val,
val + 1 as prev,
val + prev as val
FROM ( SELECT 1 as val )
; -- { serverError CYCLIC_ALIASES, TOO_DEEP_RECURSION }


SELECT
val,
val + 1 as prev,
val + prev as val2
FROM ( SELECT 1 as val )
;

0 comments on commit 6f8349c

Please sign in to comment.