Skip to content

Backport #108493 to 26.5: Fix crash on deeply nested expressions with raised max_parser_depth - #108899

Merged
alexey-milovidov merged 3 commits into
26.5from
backport/26.5/108493
Jun 30, 2026
Merged

alexey-milovidov merged 3 commits into
26.5from
backport/26.5/108493

Conversation

@robot-clickhouse

@robot-clickhouse robot-clickhouse commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Original pull-request #108493
Cherry-pick pull-request #108831

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.5.5.10

@robot-clickhouse robot-clickhouse added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [bb478d0]

Summary: ✅

alexey-milovidov and others added 2 commits June 30, 2026 08:37
`ParserCollectionOfLiterals::parseImpl` builds an array/tuple/map literal
iteratively with an explicit stack of layers. When a nested collection was
finished it was appended to its parent layer with
`layers.back().arr.push_back(literal->value)`, which deep-copies the whole
nested `Field` accumulated so far. For a deeply nested literal such as
`[[[ ... ]]]` this made parsing quadratic in the nesting depth.

`literal` is a local `ASTLiteral` that is discarded immediately after this
line (only the outermost layer is kept as `node`), so its value can be moved
into the parent instead of copied. This makes the parse linear.

This is needed for the backported test `04412_deep_nested_literal_format`.
It is tagged `no-fasttest, no-debug, no-sanitizers`, but the stress test job
deliberately ignores `no-{build}` tags (every test must run under stress), so
`04412` runs under `Stress test (amd_tsan)`. With the quadratic parse, building
the depth-20000 literal in `formatQuery` took ~1620s under ThreadSanitizer and,
being non-cancellable, tripped the hung-check ("Hung check failed, possible
deadlock found"). With the linear parse the literal is built quickly and
`formatQuery` still reports `TOO_DEEP_RECURSION` (code 306) from the
`FieldVisitorToString` stack guard, exactly as the test expects.

This mirrors the same fix applied to the master change in #108892 and to the
26.6 backport in #108832.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108899&sha=573ba507851cfb5c2c745dee34924cbdbf4fe08a&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

The only red was Stress test (amd_tsan) → "Hung check failed, possible deadlock found", caused by this PR's own backported test 04412_deep_nested_literal_format.

Root cause: that test is tagged no-fasttest, no-debug, no-sanitizers, but the stress job deliberately ignores no-{build} tags and runs every test, so 04412 runs under ThreadSanitizer. ParserCollectionOfLiterals::parseImpl appended each finished nested collection to its parent with layers.back().arr.push_back(literal->value), deep-copying the whole accumulated nested Field. For a depth-20000 literal such as [[[ ... ]]] this is quadratic in the depth, so building it in formatQuery took ~1620s under TSan and, being non-cancellable, tripped the hung check.

literal is a local that is discarded right after this line (only the outermost layer is kept as node), so its value can be moved into the parent. With the linear parse the literal is built quickly and formatQuery still reports TOO_DEEP_RECURSION (code 306) from the FieldVisitorToString stack guard, exactly as the test expects.

Pushed 573ba507851..bb478d06b85 (also merged origin/26.5 to bring the branch up to date; no conflicts). This mirrors the same fix already applied to the master change in #108892 and to the 26.6 backport in #108832. No other CI failures and no unresolved review threads.

@alexey-milovidov
alexey-milovidov merged commit 75a2916 into 26.5 Jun 30, 2026
34 checks passed
@alexey-milovidov
alexey-milovidov deleted the backport/26.5/108493 branch June 30, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants