Repository navigation
Reject the Detached serialization kind in data received from a client - #117699
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]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [c203d8e] Summary: ❌
AI ReviewSummaryThis PR hardens Findings
Tests
Final VerdictStatus: Minimum required actions: reject kind stacks whose kinds the declared type cannot instantiate, and add one regression test for that path. LLVM Coverage ReportMeasured on commit c203d8e.
Changed lines: Changed C/C++ lines covered: 104/106 (98.11%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units3133 translation units recompiled, 17042 s compile time in total, 3133 of them have a recent master baseline. |
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]>
Backport #117699 to 26.9: Reject the Detached serialization kind in data received from a client
Cherry pick #117699 to 26.7: Reject the Detached serialization kind in data received from a client
…ata received from a client
Cherry pick #117699 to 26.8: Reject the Detached serialization kind in data received from a client
…ata received from a client
Backport #117699 to 26.8: Reject the Detached serialization kind in data received from a client
Cherry pick #117699 to 26.3: Reject the Detached serialization kind in data received from a client
…ata received from a client
Backport #117699 to 26.7: Reject the Detached serialization kind in data received from a client
Backport #117699 to 26.3: Reject the Detached serialization kind in data received from a client
… kind in data received from a client
A Native TCP client chooses the serialization kind of every column it sends.
Kind::DETACHEDis an internal transport representation for parallel blocks marshalling: it makesNativeReaderbuild aColumnBLOBof raw peer-supplied bytes while the block keeps the declared type of the column, and it was applied unconditionally, unlikeSPARSE. A client could therefore send a column declaredMap(UInt64, UInt64)whose runtime column is aColumnBLOB, and any laterassert_cast<const ColumnMap &>on it — a plainstatic_castin release builds — read attacker-controlled bytes.A reader now declares which kinds the peer may select, with a new
ISerialization::KindSet.NativeReaderexcludesDetachedby default;Connection::initBlockInputis the only reader that accepts it, since the server may marshall result blocks and every remote source pipe converts the blobs back. Tuple elements never accept it.Kind stacks coming off the wire are also checked for shape: they must start with
Default,Detachedmust be outermost, and theCOMBINATIONencoding may not announce more kinds than exist.docs/reference/interfaces/specs/NativeFormat.mdxis updated.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash when a client sends a block over the Native TCP protocol that selects the internal
Detachedserialization kind for a column.Workflow [PR]
Sync PR [sync-upstream/pr/117699]
Version info
26.10.1.338-master(included in26.10and later)26.9.1.1626,26.8.11.7,26.7.14.19,26.3.33.133