Repository navigation
datatypes: reject corrupt array offsets before indexing the nested column (#11207) - #11325
ti-chi-bot wants to merge 14 commits into
Conversation
…lumn Unchecked sizes can wrap and leave ColumnArray offsets past the nested column, so later reads walk off the allocation.
Reuse the bulk decoder rollback to avoid staging array offsets. Cover failed tuple and string appends to populated columns.
Padding and power-of-two rounding could shrink a huge Array(Float32) buffer while the reader still copied the full byte count.
Keep oversized-count input bytes alive, cover multiplication overflow at 2^62, and verify rollback after a completed nested array followed by a short tuple component.
Move maxAllocSize and maxReserveSize to PODArrayBase and use the same bounds in allocation-size validation. Test the actual allocation path at and above both limits without allocating the huge buffers.
Discard partially decoded columns on failure instead of keeping recursive checkpoints and rolling back subcolumns. Retain overflow, offset, and nested-component length validation, and test rejection without reusing failed columns.
Retain the existing empty-elements exception while validating non-empty nested columns. Cover both offset encodings and stream layouts, and verify getDataAt still rejects reads past empty elements.
|
This cherry pick PR is for a release branch and has not yet been approved by triage owners. To merge this cherry pick:
DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
This is an automated cherry-pick of #11207
What problem does this PR solve?
Issue Number: close #11206
Problem Summary:
Array bulk deserialization could accept overflowing or decreasing offsets, or non-zero offsets with missing element data. For example, position-independent sizes
2^63and2^63 + 4wrap to offsets[2^63, 4]. Checking only the last offset against the nested column does not detect the earlier invalid offset.These offsets can cause out-of-bounds reads in consumers such as vector casts and distance functions. TiDB
VECTORusesArray(Float32), and the bulk decoder is used by MPP exchange chunks and columnar storage reads. Large element counts can also overflow buffer allocation arithmetic and produce an undersized allocation.What is changed and how it works?
initial_size + limitbefore resizing the offsets column, and check cumulative offset addition before storing each offset.Valid empty arrays with zero offsets remain supported. The inherited Nested ALTER exception allowing non-zero offsets with an empty nested column is removed. DeltaMerge handles columns absent after DDL in
DMFileReader::readColumnby creating default values directly.The new offset-count, cumulative-offset, monotonicity, and nested-length checks throw
LOGICAL_ERROR. PODArray allocation-size overflow checks throwTOO_LARGE_ARRAY_SIZE. A decoding failure may leave partially decoded data, so callers must discard the destination column. Representable requests can still attempt large allocations.Position-independent decoding retains the original preallocation and indexed writes, then shrinks the offsets to the number of sizes actually read at EOF. It adds one offset-count overflow check per batch and one cumulative-offset overflow check per row. Absolute offsets receive an additional sequential validation pass.
Check List
Tests
Unit-test coverage includes both offset encodings, single and separate streams, batch appends, early EOF, offset-count and cumulative-offset overflow, missing or truncated elements and components, valid empty arrays, and PODArray allocation boundaries.
Local validation: compiled
DataTypeArray.cppandgtest_data_type_array.cpp, checked their formatting with clang-format, and rangit diff --check. The fullgtests_dbmssuite was not run locally.Side effects
Documentation
Release note
Summary by CodeRabbit