Repository navigation
Fix out-of-bounds read on truncated compact Variant discriminators - #120252
Conversation
|
Workflow [PR], commit [d575724] Summary: ❌
AI ReviewSummaryThe PR hardens Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit d575724.
Changed lines: Changed C/C++ lines covered: 19/21 (90.48%) · Uncovered code |
| SerializationNumber<ColumnVariant::Discriminator>::create()->deserializeBinaryBulk(discriminators, *stream, limit_in_granule, 0); | ||
| size_t start = discriminators_data.size() - limit_in_granule; | ||
| size_t start = discriminators_data.size(); | ||
| SerializationNumber<ColumnVariant::Discriminator>::deserializeBinaryBulk(discriminators_data, *stream, limit_in_granule); |
There was a problem hiding this comment.
This still diverges from the top-level Variant reader: the freshly read discriminators are never bounds-checked before being interpreted. A corrupt PLAIN compact granule like [100] for Variant(UInt8) makes SELECT v.UInt8 fall through to the variant_limit == 0 path and materialize a default, and SELECT v.UInt8.null materialize 1, instead of rejecting the stream as INCORRECT_DATA. Please mirror the discriminator bounds check here before turning these bytes into row counts.
There was a problem hiding this comment.
To reach that, we'd need a corrupt part with either checksums off or somehow bypassed. Does not hurt, but I am not sure it's needed in this security fix, especially considering that I will backport it. If human reviewer finds this useful, I will change top-level reader too
| SerializationNumber<ColumnVariant::Discriminator>::create()->deserializeBinaryBulk(discriminators, *stream, limit_in_granule, 0); | ||
| size_t start = discriminators_data.size() - limit_in_granule; | ||
| size_t start = discriminators_data.size(); | ||
| SerializationNumber<ColumnVariant::Discriminator>::deserializeBinaryBulk(discriminators_data, *stream, limit_in_granule); |
There was a problem hiding this comment.
This PR changes Native Variant COMPACT decoding, but the canonical spec in docs/reference/interfaces/specs/NativeFormat.mdx still says that only BASIC mode is specified for Variant. Repo policy for Native-format work is to keep the spec in sync in the same PR, so the COMPACT granule layout and the requirement to reject truncated discriminator payloads need to be documented there as well.
There was a problem hiding this comment.
We do not need to specify each invalid input check in native format description
Variant discriminators
#120610
Backport #120252 to 26.9: Fix out-of-bounds read on truncated compact `Variant` discriminators
Backport #120252 to 26.8: Fix out-of-bounds read on truncated compact `Variant` discriminators
…ed compact `Variant` discriminators
Resolved the conflict in `SerializationVariant::deserializeCompactDiscriminators` and `SerializationVariantElement::deserializeCompactDiscriminators`. Master dropped the `rows_offset` parameter and moved to the static `SerializationNumber::deserializeBinaryBulk` overload that takes the data container; 26.3 has neither, so the branch's call shape is kept and only the actual fix is applied: take `start` before the read and reject a short read with `CANNOT_READ_ALL_DATA`, instead of computing `start` as `size() - limit_in_granule`, which underflows and reads out of bounds when the stream is truncated. Verified on the 26.3.33.24 release binary that the three truncated `Native` streams in the new test currently fail with `INCORRECT_DATA` from reading past the buffer (for example `Invalid discriminator value 194 (num_variants = 1)`), so the test exercises the patched path on this branch, and that the rest of the test already matches its reference. Original pull-request #120252 Cherry-pick pull-request #120607 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Resolved the conflict in `SerializationVariant::deserializeCompactDiscriminators` and `SerializationVariantElement::deserializeCompactDiscriminators`. Master dropped the `rows_offset` parameter and moved to the static `SerializationNumber::deserializeBinaryBulk` overload that takes the data container; 26.7 has neither, so the branch's call shape is kept and only the actual fix is applied: take `start` before the read and reject a short read with `CANNOT_READ_ALL_DATA`, instead of computing `start` as `size() - limit_in_granule`, which underflows and reads out of bounds when the stream is truncated. Verified on the 26.7.13.12 release binary that the three truncated `Native` streams in the new test currently fail with `INCORRECT_DATA` from reading past the buffer (for example `Invalid discriminator value 194 (num_variants = 1)`), so the test exercises the patched path on this branch, and that the rest of the test already matches its reference. Original pull-request #120252 Cherry-pick pull-request #120609 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… `Variant` discriminators
… `Variant` discriminators
Backport #120252 to 26.3: Fix out-of-bounds read on truncated compact `Variant` discriminators
Backport #120252 to 26.7: Fix out-of-bounds read on truncated compact `Variant` discriminators
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an out-of-bounds read when reading a
Variantcolumn from a truncatedNativestream using compact discriminators serialization.Workflow [PR]
Sync PR [sync-upstream/pr/120252]
Version info
26.9.1.1596,26.8.7.13,26.7.14.3,26.3.33.120