Skip to content

Reject too deep cursors instead of exhausting the stack - #127286

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-field-binary-recursion
Oct 23, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-field-binary-recursion

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Two ways to overflow the stack with a cursor of absurd depth:

  1. A binary Field was deserialized recursively without a stack check. A forged clickhouse.refresh-cursor in the snapshot summary of an Iceberg target of an incremental refreshable materialized view, made of deeply nested arrays, overflowed the stack of the background thread during the next refresh. Now getBinaryValue calls checkStackSize.
  2. A cursor tree is built from dotted paths and then traversed and destroyed recursively, one level per path component. A path with many components overflowed the stack, both in STREAM CURSOR {'a.a.a...': 1} of any query (in the parser, on the server or in the client) and in a forged refresh cursor. Now buildCursorTree limits the depth to 256 (real cursors look like partition_id.block_number).

The test covers STREAM CURSOR over HTTP and both kinds of forged refresh cursors in IcebergLocal metadata.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix stack overflow on a cursor of a huge depth, either in STREAM CURSOR of a query or in the refresh cursor stored in the Iceberg metadata of a target of an incremental refreshable materialized view.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127286]

Version info

  • Merged into: 26.11.1.672-master (included in 26.11 and later)
  • Backported to: 26.10.2.100, 26.9.26.12, 26.8.35.14, 26.3.61.10

alexey-milovidov and others added 2 commits October 21, 2026 21:58
A binary `Field` is deserialized recursively without a stack check, so a forged
`clickhouse.refresh-cursor` in Iceberg metadata with deeply nested arrays overflowed
the stack of the background thread doing an incremental refresh. Call `checkStackSize`
in `getBinaryValue`.

A cursor tree is built from dotted paths, and then traversed and destroyed recursively,
so a path with many components (e.g. in `STREAM CURSOR {'a.a.a...': 1}` of any query,
or in a forged refresh cursor) also overflowed the stack. Limit the depth of the tree
in `buildCursorTree`.

ClickHouse/clickhouse-private#82526

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client parses the query itself, so the deep `STREAM CURSOR` must go over HTTP to reach the server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8d34449]

Summary: ✅


AI Review

Summary

The PR guards recursive binary Field decoding and limits cursor paths to 256 components, preventing stack overflow from deeply nested STREAM CURSOR input and forged refresh cursors in IcebergLocal metadata. No actionable findings. The focused regression test passed 50 times under ARM ASan/UBSan on commit d9d5b7d5 in the targeted CI job.

Final Verdict

✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... labels Oct 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8d34449e6 with master 4d1bce945 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 179708c7e; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 11 s compile time in total, 8 of them have a recent master baseline.

Job report

@Michicosun Michicosun self-assigned this Oct 22, 2026
@watson-ch

watson-ch Bot commented Oct 22, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2200

Labels added:

  • v26.6-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit 657a9d0 Oct 23, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-field-binary-recursion branch October 23, 2026 20:00
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 23, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #127286 to 26.10: Reject too deep cursors instead of exhausting the stack
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #127286 to 26.9: Reject too deep cursors instead of exhausting the stack
alexey-milovidov added a commit that referenced this pull request Oct 24, 2026
Resolve conflicts of the cherry-pick of #127286 to 26.3:
- `src/Core/Streaming/CursorTree.cpp` does not exist in 26.3 (streaming
  cursors are not there), so the change to it is dropped.
- The test `05441_deep_refresh_cursor` exercises `STREAM CURSOR` and the
  refresh cursor in Iceberg metadata, which do not exist in 26.3, so it is
  dropped as well.
- The `checkStackSize` call in `getBinaryValue` in `src/Core/Field.cpp`
  is kept.
robot-ch-test-poll2 added a commit that referenced this pull request Oct 24, 2026
Cherry pick #127286 to 26.3: Reject too deep cursors instead of exhausting the stack
robot-clickhouse added a commit that referenced this pull request Oct 24, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 25, 2026
Backport #127286 to 26.8: Reject too deep cursors instead of exhausting the stack
alexey-milovidov added a commit that referenced this pull request Oct 25, 2026
Backport #127286 to 26.3: Reject too deep cursors instead of exhausting the stack
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
mkmkme pushed a commit to Altinity/ClickHouse that referenced this pull request Nov 13, 2026
…-recursion

Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 16, 2026
Antalya 25.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 16, 2026
Stable 25.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Antalya 26.6 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 18, 2026
Stable 24.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 19, 2026
FIPS 25.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 19, 2026
Stable 25.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
@clickhouse-gh clickhouse-gh Bot added comp-streaming-queries Streaming queries: queries that keep reading a table as data arrives - cursors, subscriptions to ... and removed comp-refreshable-materialized-view Refreshable materialized views: scheduled/periodic refresh, refresh state machine, refresh orches... labels Nov 22, 2026
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 23, 2026
Stable 24.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Nov 23, 2026
Stable 23.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-streaming-queries Streaming queries: queries that keep reading a table as data arrives - cursors, subscriptions to ... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants