Repository navigation
Reject too deep cursors instead of exhausting the stack - #127286
Conversation
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]>
|
Workflow [PR], commit [8d34449] Summary: ✅
AI ReviewSummaryThe PR guards recursive binary Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 11 s compile time in total, 8 of them have a recent master baseline. |
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2200 Labels added:
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. |
Backport #127286 to 26.10: Reject too deep cursors instead of exhausting the stack
Backport #127286 to 26.9: Reject too deep cursors instead of exhausting the stack
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.
Cherry pick #127286 to 26.3: Reject too deep cursors instead of exhausting the stack
Backport #127286 to 26.8: Reject too deep cursors instead of exhausting the stack
Backport #127286 to 26.3: Reject too deep cursors instead of exhausting the stack
…-recursion Reject too deep cursors instead of exhausting the stack
Antalya 25.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Stable 25.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Antalya 26.6 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Stable 24.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
FIPS 25.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Stable 25.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Stable 24.3 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Stable 23.8 Backport of ClickHouse#127286 - Reject too deep cursors instead of exhausting the stack
Two ways to overflow the stack with a cursor of absurd depth:
Fieldwas deserialized recursively without a stack check. A forgedclickhouse.refresh-cursorin 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. NowgetBinaryValuecallscheckStackSize.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. NowbuildCursorTreelimits the depth to 256 (real cursors look likepartition_id.block_number).The test covers
STREAM CURSORover HTTP and both kinds of forged refresh cursors inIcebergLocalmetadata.Changelog category (leave one):
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 CURSORof 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
26.11.1.672-master(included in26.11and later)26.10.2.100,26.9.26.12,26.8.35.14,26.3.61.10