Fix out-of-bounds read in SerializationReplicated on the native protocol - #112331
Open
Avogar wants to merge 2 commits into
Open
Fix out-of-bounds read in SerializationReplicated on the native protocol#112331Avogar wants to merge 2 commits into
Avogar wants to merge 2 commits into
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 <noreply@anthropic.com>
Contributor
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 20/23 (86.96%) · Uncovered code |
`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 <noreply@anthropic.com>
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.
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.