Skip to content

Fix AST fuzzer client crash rewriting a query-parameter identifier into a subcolumn accessor - #110740

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-fuzzer-subcolumn-param-identifier
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-fuzzer-subcolumn-param-identifier

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

QueryFuzzer::fuzzExpressionList has a branch (added in #110228) that rewrites a column reference c into one of its subcolumn accessors: c.null, c.1, c[0], getSubcolumn(c, ...). For a query-parameter identifier like {p:Identifier}.col, the ASTIdentifier stores the placeholder as an empty name_part plus a name_params child. Cases 0 and 3 copied name_parts (including that empty part) and rebuilt the identifier via make_intrusive<ASTIdentifier>(std::move(parts)) without the name_params, so the constructor took the non-parametrized branch and tripped chassert(!part.empty()), aborting clickhouse-client (SIGABRT) mid-fuzzing.

The fix skips parameter identifiers in this branch (!ident->isParam()): the branch is for column references, and query-parameter identifiers are not fuzzed here.

Found by the AST fuzzer (client-side abort). CIDB shows this hitting several unrelated PRs and master starting 2026-07-16, e.g. AST fuzzer (amd_tsan):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110641&sha=9be63c5843bb3d9cdb7267ea5e81ce6a025b5155&name_0=PR&name_1=AST%20fuzzer%20%28amd_tsan%29

Client-side backtrace: QueryFuzzer::fuzzExpressionList (QueryFuzzer.cpp:3515) -> make_intrusive<ASTIdentifier> -> ASTIdentifier::ASTIdentifier (ASTIdentifier.cpp:48) -> chassert(!part.empty()).

Note: the same !part.empty() assertion can also be reached server-side (IdentifierNode::toASTImpl) via an unresolved {p:Identifier} inside a named WINDOW clause; that is a separate parser issue fixed by #110506. This PR fixes only the client-side fuzzer path, which #110506 does not touch.

Verified locally (debug build): the AST fuzzer crashes client-side without this change and no longer does with it.

…to a subcolumn accessor

QueryFuzzer::fuzzExpressionList's subcolumn-rewrite branch turns a column
reference like c into c.null / c.1 / c[0] etc. For a query-parameter
identifier such as {p:Identifier}.col, the ASTIdentifier carries the
placeholder as an empty name_part plus a name_params child. Cases 0 and 3
copied name_parts (including the empty part) and rebuilt the identifier via
make_intrusive<ASTIdentifier>(std::move(parts)) without name_params, so the
constructor took the non-parametrized branch and hit chassert(!part.empty()),
aborting clickhouse-client (SIGABRT) during AST fuzzing.

Skip parameter identifiers in this branch (isParam()); the branch is meant
for column references, and query-parameter identifiers are not fuzzed here.

Found by the AST fuzzer (client-side abort, QueryFuzzer.cpp -> ASTIdentifier.cpp
!part.empty()).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse client --param_p=xx --query-fuzzer-runs=6000 --queries-file q.sql with q.sql = SELECT {p:Identifier}.c1 AS x, sum({p:Identifier}.c2) FROM numbers(1) GROUP BY x aborts the client (QueryFuzzer.cpp:3515 -> ASTIdentifier.cpp:48) on the first run against a pristine build.
b Root cause explained? The subcolumn-rewrite branch (cases 0/3) copies ident->name_parts for a {p:Identifier}.col identifier. That identifier stores the placeholder as an empty name_part + a name_params child. The branch rebuilds make_intrusive<ASTIdentifier>(std::move(parts)) WITHOUT name_params, so the ctor takes the non-parametrized path and chassert(!part.empty()) fires on the empty part -> SIGABRT.
c Fix matches root cause? Yes. Skip parameter identifiers (!ident->isParam()) so the branch only rewrites real column references, exactly the case it was written for.
d Test intent preserved / new tests added? This is a fuzzer-harness (test-tool) fix, not a server code path. No behavior for user queries changes; the fuzzer simply no longer builds an invalid ASTIdentifier from a parameter placeholder.
e Both directions demonstrated? Yes. Pristine build (Build ID 698EF36A): client-side crash on run 1. With fix (Build ID 4D65DA9D): 0 client-side QueryFuzzer.cpp:3515 crashes across 5 x 6000-run fuzz passes.
f Fix is general across code paths? The identical !part.empty() assertion is also reachable server-side via IdentifierNode::toASTImpl for an unresolved {p:Identifier} inside a named WINDOW clause. That is a separate parser bug and is fixed by #110506 (which does not touch the fuzzer). This PR fixes the one client-side fuzzer path #110506 leaves unaddressed.
g Fix generalizes across inputs? N/A (fuzzer-harness fix, not a server code bug). The guard covers every query-parameter identifier regardless of the parameter type.
h Backward compatible? N/A (fuzzer-harness fix, no user-visible behavior, no settings/format change).
i Invariants and contracts preserved? Yes. Upholds the ASTIdentifier constructor contract that non-parametrized identifiers must have no empty name_part. The branch was violating it by dropping name_params; the guard restores the invariant.

Session id: cron:clickhouse-worker-slot-2:20260716-191000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim — small AST-fuzzer fix: the subcolumn-rewrite branch you added in #110228 aborts the client when the identifier is a {p:Identifier} query-parameter placeholder (empty name_part rebuilt without name_params -> chassert(!part.empty())). Guarded with !ident->isParam(). Separate from the server-side WINDOW-clause manifestation in #110506.

@PedroTadim

Copy link
Copy Markdown
Member

This is done by #110712 and better there

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

Successfully merging this pull request may close these issues.

2 participants