Repository navigation
Stop the ARRAY[ constructor lookahead at the end of the statement - #128475
alexey-milovidov merged 2 commits into
Conversation
isArrayConstructorWithKeyword (added in ClickHouse#124763) decides whether `ARRAY[` starts the array constructor by scanning forward for a depth-0 comma or closing bracket. The scan did not stop at `;`, so for an `ARRAY[` that is not closed in its own statement it read tokens of the next statement. Tokens::max() follows every token a parser looks at and is what tryParseQuery reports as the error position, while the generic error branch passes the end of the first statement as the end of the excerpt. writeQueryAroundTheError then computed `end - begin` with begin > end, and the unsigned length wrapped: the message contained bytes read past the end of the query text, and ASan builds aborted (found by select_parser_fuzzer, heap-buffer-overflow in UTF8::computeBytesBeforeWidth). A `;` token cannot be inside the brackets of one statement, so the scan now returns false there: such an `ARRAY[` is not an array constructor, and the parser fails at the `;` exactly as before ClickHouse#124763. Valid queries are not affected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261101-115900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261101-110900 |
|
cc @alexey-milovidov @george-larionov, could you review this and add the |
|
Workflow [PR], commit [678f9e3] Summary: ✅
AI ReviewSummaryThe PR stops Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 94e53adEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261101-163005 |
Backport #128475 to 26.10: Stop the `ARRAY[` constructor lookahead at the end of the statement
Related: #124763
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a syntax error message that contained bytes read past the end of the query text when an
ARRAY[was not closed before the;, for exampleSELECT ARRAY[f(1); 2]. The error points at the;again.Description
Found by the nightly
select_parser_fuzzer(ASanheap-buffer-overflowinUTF8::computeBytesBeforeWidthfromwriteQueryAroundTheError): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c189bd99fbda59c78489a6734c49397533bdd591&name_0=NightlyFuzzers&name_1=libFuzzer%20tests.On 26.10.2.103-stable,
SELECT ARRAY[f(1); 2]sent over HTTP returnsSyntax error: failed at position 21 (]): ]followed by bytes read past the end of the query text; 26.9.25.15 returnsfailed at position 18 (end of query): ;..isArrayConstructorWithKeyword(#124763) scans the tokens afterARRAY[for a depth-0 comma or closing bracket and does not stop at;, so it reads into the next statement. The tokens it looks at moveTokens::max(), whichtryParseQueryreports as the error position, while the excerpt ends at the first statement's;.writeQueryAroundTheErrorthen computesend - beginwithbegin > end, and the unsigned length wraps.A
;now ends the scan withfalse. A;token cannot be inside the brackets of one statement, so such anARRAY[is not an array constructor, and the parser fails at the;as before #124763. No valid query changes meaning. Within one statement the scan still reads to the end of the statement (SELECT ARRAY[f(1) FROM treports the end of the query), which stays inside the text the message shows.Validation: the ASan build of master aborts on the fuzzer input,
SELECT ARRAY[f(1); 2]andSELECT ARRAY[f(1); SELECT 1, 2]; with this change (debug and ASan builds) all three returnSYNTAX_ERRORat the;without an ASan report. The new test fails on master and with the newcaseremoved, and passes 50/50 randomized runs; the syntax-error and Trino dialect tests pass unchanged.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128475]
Version info
26.11.1.1159-master(included in26.11and later)