Skip to content

Cherry pick #120885 to 26.3: Guard the constant-to-literal walks with checkStackSize - #124705

Merged
PedroTadim merged 8 commits into
backport/26.3/120885from
cherrypick/26.3/120885
Oct 12, 2026
Merged

PedroTadim merged 8 commits into
backport/26.3/120885from
cherrypick/26.3/120885

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #120885

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Avogar and others added 8 commits September 18, 2026 17:35
Turning a constant into an AST literal walks the value recursively, and for
`Dynamic`/`JSON` the nesting is part of the value rather than of the query
text, so no parser limit bounds it: a `JSON` path holding a `Dynamic` holding
a `JSON` costs three stack frames per level, and the depth comes straight from
the binary value. A deeply nested value therefore ran past the stack guard
page and killed the process instead of failing the query.

Add `checkStackSize` to `getFieldFromColumnForASTLiteralImpl` and
`columnConstantToExactLiteralASTImpl`, which turns this into
`TOO_DEEP_RECURSION`, matching what the `Field` visitors already report for
the same data.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reading a value as a `Field` walks the column recursively, and a `JSON` path
holding a `Dynamic` holding a `JSON` cycles between `ColumnObject`,
`ColumnDynamic` and `ColumnVariant` once per nesting level. The nesting is
part of the value rather than of the query text, so no parser limit bounds
it, and a deeply nested value ran past the stack guard page and killed the
process.

Add `checkStackSize` to `ColumnObject::operator[]` and `ColumnDynamic::get`,
the two entry points of that cycle, so it reports `TOO_DEEP_RECURSION`
instead. Found by the AST fuzzer, which mutated the constant from the test
added here into `if(<deeply nested Dynamic>, 1, 2)`: constant folding reads
the condition as a `Field` and enters the walk.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Guard the constant-to-literal walks with checkStackSize
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Oct 8, 2026
@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Dear @vdimir, @Avogar, this cherry-pick PR has not been updated for 3d0h9m54s. Please resolve the conflicts to backport #120885, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@PedroTadim
PedroTadim merged commit 5328587 into backport/26.3/120885 Oct 12, 2026
180 of 181 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/120885 branch October 12, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants