Repository navigation
Fix out-of-bounds read in SerializationReplicated on the native protocol - #112331
Conversation
`SerializationReplicated::deserializeBinaryBulkWithMultipleStreams` read a
client-supplied replicated-index buffer from the native TCP protocol and
validated only the index row count, not the index values. Every
`ColumnReplicated` accessor then dereferences `nested_column[index]` without
a bound, so a crafted `REPLICATED`-serialized column whose indexes point past
the nested ("elements") column produces an out-of-bounds read when the column
is materialized.
Validate every deserialized index against the number of nested elements
(throwing `INCORRECT_DATA`) before attaching the indexes, mirroring the
per-discriminator check already done in `SerializationVariant`.
Reachable only over the native TCP protocol (negotiated revision >=
`DBMS_MIN_REVISION_WITH_REPLICATED_SERIALIZATION`); the format layer builds
`NativeReader` with `server_revision = 0`, so `REPLICATED` is never read there.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [541c52c] Summary: ✅
AI ReviewSummaryThis PR closes the two malformed-input paths that could leave Findings
Final VerdictNot ready to merge until the |
`checkDeserializedIndexes` only proved that replicated indexes are less than the advertised `num_elements`; it never proved that `nested->deserializeBinaryBulkWithMultipleStreams` actually produced `num_elements` rows. Primitive bulk readers such as `SerializationNumber::deserializeBinaryBulk` short-read on EOF instead of throwing, and `NativeReader::readData` only checks the top-level `column->size()`, which for `ColumnReplicated` is the index count, not the nested column size. So a client could send in-range indexes, advertise `num_elements = N`, truncate the elements payload, and still hand an out-of-bounds-capable `ColumnReplicated` to the executor. Verify `column_replicated.getNestedColumn()->size() == num_elements` after the nested deserialization and throw `INCORRECT_DATA` on mismatch, mirroring the post-read consistency checks in `SerializationArray` and `SerializationVariant`. Extend the regression test with a second scenario covering in-range indexes plus a truncated elements stream. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 25/28 (89.29%) · Uncovered code |
Backport #112331 to 26.7: Fix out-of-bounds read in SerializationReplicated on the native protocol
|
Hi @Avogar @antonio2368 — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
Backport #112331 to 26.3: Fix out-of-bounds read in SerializationReplicated on the native protocol
Backport #112331 to 26.5: Fix out-of-bounds read in SerializationReplicated on the native protocol
Backport #112331 to 26.6: Fix out-of-bounds read in SerializationReplicated on the native protocol
`SerializationReplicated::deserializeBinaryBulkWithMultipleStreams` had three sibling checks that still threw `LOGICAL_ERROR` for conditions decided purely by untrusted native-protocol bytes: - a non-empty target column, reachable via a `Sparse`-over-`Replicated` kind stack (a fresh `ColumnSparse` always seeds one default value, which is then handed to the nested `Replicated` deserialization); - an index row count that disagrees with the block row count; - an unsupported index-type width. In debug and sanitizer builds `LOGICAL_ERROR` is routed to `abortOnFailedAssertion`, so a crafted block aborts the server; in release builds it is the wrong error class and trips CI checks that scan logs for `Logical error`. Change all three to `INCORRECT_DATA`, matching the checks added in ClickHouse#112331 and the analogous `SerializationLowCardinality` code, and extend the native-protocol regression test with the three scenarios. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…zationReplicated on the native protocol
…zationReplicated on the native protocol
…zationReplicated on the native protocol
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix out-of-bounds read in SerializationReplicated on the native protocol on corrupted indexes data.
Version info
26.7.4.11,26.6.3.26,26.5.7.35,26.3.18.18