Repository navigation
Cherry pick #117699 to 26.3: Reject the Detached serialization kind in data received from a client - #121317
Merged
robot-clickhouse-ci-1 merged 11 commits intoSep 22, 2026
Conversation
A Native TCP client chooses the serialization kind of every column of the
blocks it sends. `Kind::DETACHED` is an internal transport representation
for parallel blocks marshalling: it makes `NativeReader` build a
`ColumnBLOB` holding raw peer-supplied bytes, while the block keeps the
declared type of the column. It was applied unconditionally in
`IDataType::wrapSerializationBasedOnKindStack`, unlike `SPARSE` one line
above it.
So a client could send an external table with a column declared
`Map(UInt64, UInt64)` whose runtime column is a `ColumnBLOB`, and
`SELECT mapConcat(x) FROM e` then ran `assert_cast<const ColumnMap &>`
(a plain `static_cast` in release builds) over attacker-controlled bytes.
Make the reader declare which kinds the peer may select, with a new
`ISerialization::KindSet`. `NativeReader` accepts everything except
`Detached` by default, so `TCPHandler`, the exchange sources and the
temporary data streams are all covered without being touched.
`Connection::initBlockInput` is the only reader that accepts every kind,
because the server may marshall result blocks and every remote source
pipe converts the blobs back. Tuple elements never accept `Detached`.
Also validate the shape of a kind stack that comes off the wire: it has
to start with `Default`, `Detached` has to be the outermost kind, and the
`COMBINATION` encoding may not announce more kinds than exist, which
previously allowed building an arbitrarily deep nesting of serializations
from a stream-supplied count. The `COMBINATION` branch now replaces the
kind stack instead of appending to the pre-seeded `{Default}`, which
matches what the writer produces.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Each kind wraps the serialization exactly once, so a repeated kind nests a
column inside its own layout. `{Default, Sparse, Sparse}` builds a
`ColumnSparse` whose values column is itself sparse, and
`ColumnSparse::convertToFullColumnIfSparse` reaches the generic
`IColumn::createWithOffsets`, which materializes through `cloneEmpty` of that
values column - so the result stays sparse where callers expect a full column
of the declared type.
The kind stack is chosen by the peer, so reject the repeat in `checkKindStack`
next to the other shape rules. The `COMBINATION` length bound stays: it refuses
an impossible peer-declared count before reading that many kinds, rather than
restating the shape rule.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ColumnBLOB` is a transport representation produced by the `Detached` serialization kind, but it was not handled by the helpers that strip such representations, so it reached consumers that go on to `assert_cast` the column to the one its declared type produces. `SerializationNumber::serializeText`, for example, casts to `ColumnVector`, which in a release build reads the `ColumnBLOB` as if it were one. Make it a first-class representation wrapper instead of adding checks at the consumers: `IColumn::convertToFullColumnIfDetached` joins the existing `convertToFullColumnIfSparse` / `convertToFullColumnIfReplicated` family, and both `convertToFullIfWrapped` and `removeSpecialRepresentations` chain it first, since the BLOB holds the serialized form of everything below it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A kind stack describes nested column wrappers, so only a subsequence of
`Default`, `Sparse`, `Replicated`, `Detached` is buildable: `ColumnSparse` can
sit inside `ColumnReplicated` but not the other way round, and nothing wraps a
`ColumnBLOB`. The peer chooses the stack, and any other order describes a
layout no writer produces and that materialization does not unwrap back to the
declared type - `ColumnSparse` over `ColumnReplicated` materializes through
`IColumn::createWithOffsets` into another `ColumnReplicated`.
Check the order instead of the two narrower rules it subsumes, so a repeated
kind and a non-outermost `Detached` are rejected by the same rule. The order is
not the order of the `Kind` enum, whose values are part of the Native format.
`04616_replicated_serialization_oob_index_native_protocol` sends
`{Default, Replicated, Sparse}`, which is now rejected while the kind stack is
read rather than by the non-empty column check in `SerializationReplicated`.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reject the Detached serialization kind in data received from a client
Contributor
Author
|
Dear @KochetovNicolai, @Diskein, @Avogar, this PR is opened while #117699 was marked as backported. The If the cherry-pick is not needed anymore, then just close this PR. |
Conflict resolution: * `docs/reference/interfaces/specs/NativeFormat.mdx` — accepted the deletion. The 26.3 branch has no `docs/reference/` tree; its `docs/en/interfaces/formats/Native.md` is a stub with no wire-format section, so there is nothing to carry the spec change into. * `src/Columns/IColumn.h` — kept the 26.3 name `convertToFullIfNeeded` (master renamed it to `convertToFullIfWrapped` and dropped `convertToFullColumnIfLowCardinality` from the chain; 26.3 still keeps both). Added `convertToFullColumnIfDetached` and put it first in the chain, as on master. Renamed the use in the new `gtest_column_blob.cpp` accordingly. * `src/DataTypes/Serializations/SerializationInfo.h` — kept `checkKindStack` and dropped `writeJSONFields`, which does not exist in 26.3. * `src/DataTypes/Serializations/SerializationInfo.cpp` and `gtest_serialization_info.cpp` — kept the includes the new code needs and dropped the ones only master's extra tests used. * `tests/queries/0_stateless/04616_replicated_serialization_oob_index_native_protocol.python` — kept the 26.3 version. The three scenarios master has there cover fixes that are not in 26.3, and the only one this change touched (`sparseOverReplicatedScenario`) is covered by the new `04936_detached_serialization_from_client_native_protocol` test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #117699
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job