Repository navigation
Cherry pick #106395 to 26.4: Arrow IPC: fix heap out-of-bounds reads and structural validation gaps in the column reader - #107257
Merged
Conversation
The Arrow IPC reader in ArrowColumnToCHColumn trusts schema-declared
sizes and row counts without validating them against the actual bytes
present in the RecordBatch body. A malformed Arrow file can declare
N rows while providing only a few bytes of body data, causing reads of
up to hundreds of megabytes past the allocated buffer. All paths are
reachable by any user with SELECT privilege (via file(), format(), or
table functions over Arrow/ORC/Parquet/ArrowFlight inputs).
Fixed paths (24 total):
Bulk-memcpy readers (checkArrowBuffer / checkedCast* family):
readColumnWithNumericData, readColumnWithDurationData,
readColumnWithFixedStringData, readColumnWithBigIntegerFromFixedBinaryData,
readColumnWithDate32Data (fast path), readColumnWithIndexesDataImpl,
readIPv4ColumnWithInt32Data
Per-element Value() readers (checkedCast validates before the loop):
readColumnWithBooleanData, readColumnWithDate32Data (slow path),
readColumnWithDate64Data, readColumnWithTimestampData,
readColumnWithTimeData (Time32 + Time64), readColumnWithFloat16Data,
readColumnWithDecimalDataImpl, readColumnWithUUIDFromFixedBinaryData
View-struct and offsets-buffer readers:
readColumnWithViewData (view-struct buffer + per-element variadic bounds),
readColumnWithStringData (offsets buffer before per-row data check),
readColumnWithJSONData (offsets buffer + per-row data buffer),
readOffsetsFromArrowListColumn (list offsets array),
getNestedArrowColumn (list/map offsets via Flatten())
Fix approach:
- Introduce checkArrowBuffer(chunk, elem_size, col) — validates
buffers[1]->size() >= elem_size * (offset + length) before any raw
pointer arithmetic.
- Introduce typed wrappers:
checkedCast<T>() — for numeric Arrow arrays (infers elem_size from
value_type); replaces dynamic_cast at all call sites
checkedCastFSB<T>() — for FixedSizeBinary arrays (uses byte_width())
checkedCastBool() — for Boolean (bit-packed, ceiling division)
checkedCastView<T>() — for StringView/BinaryView (16-byte view structs)
checkBinaryOffsetsBuffer() — for BinaryArray offsets buffer (+1 entry)
checkViewStruct() — per-element variadic buffer bounds for view arrays
- Replace all dynamic_cast calls on Arrow array types with the
appropriate checked wrapper; use dynamic_cast only where Arrow
subtypes may appear (BinaryArray, ListArray, MapArray) since
assert_cast requires an exact type match.
Regression tests in 04307/04308/04309_arrow_oob_reads*.sh cover all 24
paths using pyarrow-crafted Arrow IPC files with inflated row counts or
shrunk buffer declarations. Every case produces a clean INCORRECT_DATA
exception on the fixed build; on an unpatched ASan build each triggers
a heap-buffer-overflow.
Related: ClickHouse/clickhouse-private#59620
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`readColumnWithBigNumberFromBinaryData`, `readColumnWithGeoData`, and `readIPv6ColumnFromBinaryData` all called `value_length(i)` or `value_offset(i)` inside a per-row loop before validating the offsets buffer size. The protection was accidental: downstream checks happened to throw `INCORRECT_DATA` for typical PoC inputs because the garbage values read from beyond the buffer failed subsequent comparisons. A crafted Arrow body where the bytes immediately after the offsets buffer look like plausible offset values could bypass those downstream checks. Fix: add `checkBinaryOffsetsBuffer(chunk, column_name)` per chunk before the first `value_offset`/`value_length` call in each of the three functions. This makes the guard explicit and unconditional, not dependent on garbage values. Regression tests added in 04309 (cases 25–27). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…p redundant static checkViewStruct accepted inline views without rejecting negative size values. size=-1 satisfies is_inline() (-1 ≤ kInlineSize=12), returning cleanly; then static_cast<size_t>(-1) in the accumulation loop wraps to SIZE_MAX, corrupting total_bytes_size and leading to a crash in the subsequent copy pass. readColumnWithBigNumberFromBinaryData and readIPv6ColumnFromBinaryData both had a validated first pass (offsets + value_length checks) but their copy loops called chunk.Value(value_i) without proving value_offset + sizeof(T) ≤ value_data()->size(). A crafted file with a valid offsets buffer but an undersized data buffer could over-read the heap in the copy loop. Fixes: - Add v.size() < 0 rejection before the is_inline() fast-path in checkViewStruct. - Add checkBinaryOffsetsBuffer + per-row data-buffer validation to the copy loops of readColumnWithBigNumberFromBinaryData and readIPv6ColumnFromBinaryData. - Remove redundant static from checkViewStruct (already in anonymous namespace). Regression tests added in 04309 (cases 28–30). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…n tests Issue A (arithmetic overflow): checkArrowBuffer, checkBooleanBuffer, and checkBinaryOffsetsBuffer computed required byte counts with unchecked size_t multiplication. A crafted row count near 2^62 makes elem_size * count wrap to 0 mod 2^64, causing the guard to accept a tiny buffer. Fixed using __builtin_mul_overflow (data buffer) and explicit overflow-safe ceiling division (boolean/offsets). In practice reserve() always rejects the file first (Code 173), so no OOB read was reachable; the fix makes the rejection explicit and deterministic. Issue B (validity bitmap): readByteMapFromArrowColumn and all per-chunk processing paths called IsNull() / IsValid() without validating that buffers[0] (the validity bitmap) is large enough for the declared row count. A file with a valid data buffer but a truncated bitmap (e.g. 1 byte for 64 rows) would let IsNull() read adjacent body data as null flags. Fixed by adding checkValidityBitmap which checks ceil((offset+length)/8) bytes and is called at the end of checkArrowBuffer, checkBooleanBuffer, and checkBinaryOffsetsBuffer (so every data-buffer validation also validates the bitmap), plus explicitly in readByteMapFromArrowColumn. Regression tests in 04310_arrow_oob_reads_arithmetic.sh. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…tive offsets - Initialize `required = 0` in `checkArrowBuffer` and `checkBinaryOffsetsBuffer` before `__builtin_mul_overflow` writes to it, fixing the cppcoreguidelines-init-variables clang-tidy error that failed the arm_tidy build. - Replace `safe_offset + sizeof(T) > data_buf_size` with the two-part check `safe_offset > data_buf_size || sizeof(T) > data_buf_size - safe_offset` in the copy loops of `readColumnWithBigNumberFromBinaryData` and `readIPv6ColumnFromBinaryData`. The single-expression form wraps to a small value when `safe_offset` is cast from a negative `int32_t`, letting a crafted `[-8, 8]` offset pair bypass the guard. Arrow 23's IPC reader already rejects negative per-row offsets during batch loading, so this is defence-in- depth; the format string in the exception now logs the signed offset for clarity. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`total_size += chunk_length` was inside the per-row validation loop, incrementing by `chunk_length` once per row instead of once per chunk. For a valid chunk with N rows all of the expected width the loop ran N times and added N each time, reserving N² elements before inserting N. Move the increment outside the loop to match the IPv6 path, which already had it in the correct position. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replace all abbreviations with full names: checkedCastFSB → checkedCastFixedSizeBinary ArrowFSBArray → ArrowFixedSizeBinaryArray Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
getNestedArrowColumn now calls checkValidityBitmap on the parent list (or map) chunk before Flatten(). When null_count > 0, Flatten iterates over each row calling IsValid on the parent array, which reads the validity bitmap (buffers[0]). Without the preflight a crafted file with a truncated parent bitmap but valid offsets and child buffers could silently read past the end of the bitmap allocation. Regression test added as case 31 in 04309_arrow_oob_reads_offsets.sh: 128-row nullable List(Int32) with valid offsets and child data but a 1-byte parent bitmap (instead of the required 16 bytes). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add explicit guards at the top of `checkValidityBitmap`, `checkArrowBuffer`, `checkBooleanBuffer`, and `checkBinaryOffsetsBuffer` that throw `INCORRECT_DATA` when `chunk.length() < 0` or `chunk.offset() < 0`. The specific gap that motivated this: `checkBinaryOffsetsBuffer` computed `count_plus_one = static_cast<size_t>(-1) + 1 = 0`, so `required = 0` and the buffer-size check passed trivially for a crafted file with `FieldNode.length = -1`. Arrow's IPC reader accepts such a file when `RecordBatch.length` and `FieldNode.length` are consistently negative, which caused the subsequent per-row loop to iterate as if `chunk_length = SIZE_MAX`, reading `offsets[6]` past the end of a 5-row offsets buffer before the per-row bounds check caught the garbage value. The other three check functions (`checkArrowBuffer`, `checkBooleanBuffer`, `checkValidityBitmap`) were already safe via `SIZE_MAX * elem_size` overflow or `SIZE_MAX / 8` exceeding any real buffer, but the explicit guard makes the invariant self-contained and uniform across all helpers. Adds regression test `04326_arrow_oob_neg_length`. Related: #106395
In `readColumnWithBigNumberFromBinaryData` and `readIPv6ColumnFromBinaryData`, the first pass already validates that every `value_length(i) == sizeof(ValueType)` / `sizeof(IPv6)`, so using `chunk.Value(value_i).size()` in the insert is misleading — it implies the size is variable when it has been proven fixed. Use the constant `sizeof(T)` directly. Addresses review comment on #106395
In `readOffsetsFromArrowListColumn`, computing `uint64_t elements = offset - previous_offset` with unsigned arithmetic underflows when Arrow offsets are not monotonically non-decreasing. A crafted offset sequence like [0,32,33,34,35,36,37,38,32] makes the cumulative last offset wrap to exactly `nested.size()`, bypassing the `ColumnArray` constructor check (`data->size() == last_offset`) and constructing a `ColumnArray` whose interior offsets point past the inner-column allocation. Fix: use `int64_t` throughout, check that `first_offset >= 0`, and throw `INCORRECT_DATA` when any offset is less than the previous one. Adds regression test `04327_arrow_list_nonmonotonic_offsets` covering both `List` (int32 offsets) and `LargeList` (int64 offsets). Refs: ClickHouse/clickhouse-private#60305 Related: #106395
Use inner_size=64 (exact Arrow allocation unit, no padding) with offsets [0,64,65,64]. Row 1 starts at inner[64], one byte past the allocation; row 2's underflow wraps last_offset to 64 == inner_size so the ColumnArray constructor accepts it on unpatched code. SELECT arrayElement(arr,2) materialises row 1 and triggers an ASan abort on the unpatched build, confirming this is a critical OOB read, not just corrupt length output.
`ColumnArray::create` skips the `data->size() == last_offset` invariant when the child column is empty (`&& !data->empty()` short-circuit in `ColumnArray.cpp`). A crafted Arrow file with a child `FieldNode.length` patched to 0 could therefore produce a `ColumnArray` whose offsets pointed past the empty inner allocation, causing an OOB heap read. Add an explicit pre-construction check in `readColumnFromArrowColumn`: validate `off.back() == array_data_column->size()` before calling `ColumnArray::create` and `ColumnMap::create`. Regression test added to `04327_arrow_list_nonmonotonic_offsets.sh` covering `FixedSizeList` and `List` with empty child. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Two latent issues in the anonymous-namespace buffer validation helpers: 1. `chunk.offset() + chunk.length()` was computed in signed `int64_t` before being cast to `size_t`, which is UB if both values approach `INT64_MAX`. Cast each operand to `size_t` individually before adding; both are guaranteed non-negative at that point, and their sum fits in `size_t` (at most `2*INT64_MAX = UINT64_MAX-1`). Affects `checkValidityBitmap`, `checkArrowBuffer`, `checkBooleanBuffer`, and `checkBinaryOffsetsBuffer`. 2. `getValidatedBuffer` unconditionally dereferenced `buffers[1]->data()` after `checkArrowBuffer` passed. Arrow allows a null `buffers[1]` when the array is empty (`offset == 0, length == 0`); `checkArrowBuffer` passes in that case because `required == 0`. Guard with a null check and return `nullptr` when the buffer is absent — safe because callers iterate `chunk.length()` rows and the loop body is never entered. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`arrow::StructArray::field()` silently slices a child whose `FieldNode.length` is smaller than the parent struct's reported length, so independently-read fields can end up with different row counts. `ColumnTuple` never validated equal lengths, so any reader that accessed a short field past its allocation caused an OOB heap read. Add a check in the `STRUCT` branch of `readNonNullableColumnFromArrowColumn`: after converting all fields, verify each has `arrow_column->length()` rows. This closes two sibling gaps: - plain `Struct`/`Tuple` columns with one field shorter than the others - `Map` value columns shorter than key columns (Map entries go through the same `STRUCT` path, so the existing `off.back() == key_column->size()` check is now sufficient) Regression cases added to `04327_arrow_list_nonmonotonic_offsets.sh`: `struct_short_b.arrow` (field b patched 5→3) and `map_value_short.arrow` (value FieldNode.length patched 5→3 via the FlatBuffer FieldNode vector). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Two follow-ups on the Arrow OOB hardening: - `bugprone-suspicious-stringview-data-usage` (arm_tidy): read the raw pointer from the validated data buffer instead of `string_view::data()` in the BigNumber and IPv6 binary readers. - Move the list-offset monotonicity check ahead of `arrow::*ListArray::Flatten`. `Flatten` slices the values array over `offset[0]..offset[length]`, so a decreasing pair such as `[64, 0]` previously failed inside Arrow's `ArrayData::Slice` (`STD_EXCEPTION`) before the offsets reader ran. The check now lives in a shared helper called from `getNestedArrowColumn` and reused by `readOffsetsFromArrowListColumn`, so it is rejected as `INCORRECT_DATA`. Adds Class D to `04327_arrow_list_nonmonotonic_offsets.sh`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Arrow computes null_count lazily by scanning buffers[0]; a child produced by Slice/Flatten carries kUnknownNullCount, and arrow::ChunkedArray's constructor sums chunk->null_count(), scanning a possibly-truncated child bitmap before any ClickHouse validation runs. - Make `checkValidityBitmap` scan-free: validate the buffer size whenever a validity bitmap is present and never call `null_count()` (which itself triggers the out-of-bounds scan on an unknown-count slice). Call it on each flattened list child (`getNestedArrowColumn`) and each struct field before the `arrow::ChunkedArray` constructor reads it. - `FixedSizeList`: validate stride >= 0, that (offset + length) * stride does not overflow, and that the slice stays within the values array, before `Flatten`. - Guard the empty-chunk null dereference in the `Date32` numeric-hint branch and in `readColumnWithViewData`'s first pass (an empty record batch before a non-empty one can leave buffers[1] null). Regression: Classes E (list/struct child bitmap) and F (FixedSizeList short child) in 04327_arrow_list_nonmonotonic_offsets.sh. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Several malformed nested shapes still reached Arrow's slicing APIs and surfaced as `STD_EXCEPTION` from `ArrayData::Slice` instead of a clean `INCORRECT_DATA`: - A child `FieldNode.length = -1` in a Struct, List, LargeList, or FixedSizeList was sliced by `StructArray::field()` / `Flatten()` before any check. Reject a negative child length first (for FixedSizeList the value previously wrapped through `static_cast<size_t>` and bypassed the size check). - Monotonic, non-negative List/LargeList offsets can still point past the values array; validate that the last offset does not exceed `values->length()` before `Flatten`. Also guard the empty-chunk null data buffer in the two FixedSizeBinary bulk readers (`readColumnWithFixedStringData`, `readColumnWithBigIntegerFromFixedBinaryData`), matching the Date32/view fix: an empty record batch can leave buffers[1] null. Regression: Classes G (negative nested child length) and H (offsets past values) in 04327_arrow_list_nonmonotonic_offsets.sh. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fixed-width readers reserved column memory from the attacker-controlled arrow_column->length() before validating each chunk, so a malformed RecordBatch/FieldNode length (negative, or absurdly large) surfaced as CANNOT_ALLOCATE_MEMORY instead of INCORRECT_DATA. - Add a non-negative length/offset check at the entry of readColumnFromArrowColumn; it runs for every nested level too, so a negative parent (e.g. empty Struct) or child length is rejected up front. - Validate every chunk's buffer before the reserve in each fixed-width reader (numeric, duration, boolean, Date32, Date64, Timestamp, Time32/64, Decimal, Float16, FixedString, big-integer, UUID, IPv4, dictionary indexes) via a shared validateChunksBeforeReserve helper that runs the same per-chunk validator the reader already uses. An inflated length whose buffer is too small now throws INCORRECT_DATA (buffer too small / size overflow) before any allocation. The offsets/view/binary readers already validate in their first pass before reserving, and list construction validates offsets against the values length, so the LargeList huge-derived-child case is rejected by the nested numeric reader. Regression: Class I in 04327_arrow_list_nonmonotonic_offsets.sh (negative/huge top-level lengths for Int32/Bool/Decimal, empty Struct, and the LargeList case). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ield When a Struct is sliced (e.g. nested in a List/LargeList/Map whose offsets start past 0), StructArray::field() slices each child over [struct.offset, struct.offset + struct.length]. A child field shorter than that range made Arrow's ArrayData::Slice fail with STD_EXCEPTION instead of a clean INCORRECT_DATA. The struct branch only checked for a negative child length; extend it to require struct.offset + struct.length <= child.length (overflow-safe), covering the negative case too. Also remove em-dashes from comments in this file and the regression test. Regression: Class J in 04327_arrow_list_nonmonotonic_offsets.sh (List, LargeList, and Map sliced at offset 1 over a zero-length struct child field). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…llocation A fields-less (zero-field) Struct has no field buffers, so its declared row count is backed only by the validity bitmap. With no bitmap the length is unbounded, and reading the struct as a nullable Tuple() materializes a length-sized null map, so a tiny crafted file (top-level, or List/LargeList/FixedSizeList<Struct<>> via Flatten) could request an arbitrarily large allocation (MEMORY_LIMIT_EXCEEDED). - In the STRUCT branch, reject a non-empty fields-less struct chunk that has no validity bitmap, and validate the bitmap (which bounds the length) when present. - readByteMapFromArrowColumn now validates each chunk's validity bitmap before allocating the null map, so the null_count>0 case (forged-small bitmap) of any nullable column is rejected as INCORRECT_DATA before the allocation. Note: a non-null fields-less struct without a validity bitmap is now rejected; such a column carries no data and is degenerate, and its length is otherwise unbacked. Regression: Class K in 04327_arrow_list_nonmonotonic_offsets.sh (top-level, List/LargeList/FixedSizeList empty-struct huge length, and the null_count>0 case). Co-Authored-By: Claude Opus 4.8 <[email protected]>
readColumnWithJSONData reserved ColumnObject memory from arrow_column->length() before validating the Binary/LargeBinary offsets buffer, so a forged or buffer-inconsistent declared length could trigger a huge reserve() (MEMORY_LIMIT_EXCEEDED) instead of the INCORRECT_DATA the String/Binary reader returns for the same file. Validate every chunk's offsets buffer up front, before the reserve. Regression: Class L in 04327_arrow_list_nonmonotonic_offsets.sh (Binary and LargeBinary with JSON logical type, 1-row file forged to 2^30 rows). Co-Authored-By: Claude Opus 4.8 <[email protected]>
An unknown FieldNode.null_count (kUnknownNullCount = -1) made Arrow compute the count lazily by scanning buffers[0] over the declared length. With a forged-huge length and a truncated (e.g. 1-byte) bitmap this is a heap-buffer-overflow in arrow::internal::CountSetBits, and it happens inside arrow::Table::FromRecordBatches (ArrowBlockInputFormat::read), before any ClickHouse conversion runs. - Add ArrowColumnToCHColumn::checkRecordBatchValidityBitmaps, which recursively validates every validity bitmap (including nested children and dictionaries) covers its declared rows, scan-free (never calls null_count). Call it in ArrowBlockInputFormat::read before arrow::Table::FromRecordBatches. - readColumnFromArrowColumn now validates each chunk's bitmap (via the scan-free checkValidityBitmap) at its entry, before the arrow_column->null_count() used to decide nullability, covering the Parquet/ORC paths that reach it without going through FromRecordBatches. Regression: Class M in 04327_arrow_list_nonmonotonic_offsets.sh (Int32 and List with unknown null_count over a forged length and a 1-byte bitmap). Co-Authored-By: Claude Opus 4.8 <[email protected]>
The single 04327_arrow_list_nonmonotonic_offsets.sh had grown to 34 cases covering much more than list offsets. Rename and split it into smaller, themed files: - 04327_arrow_oob_list_offsets: List/LargeList offset validation (non-monotonic, decreasing-before-Flatten, offsets past values). - 04328_arrow_oob_nested_child_length: empty / short / negative nested child lengths. - 04329_arrow_oob_struct_fields: struct/map field-length mismatch, sliced struct child, fields-less struct huge length. - 04330_arrow_oob_declared_length: forged top-level length and JSON reserve-before-validate. - 04331_arrow_oob_validity_bitmap: truncated child bitmap and unknown null_count. No coverage change; each generated file and check is preserved, just regrouped. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…l bridges - Remove a trailing whitespace left in a comment (style check). - Apply the pre-Table::FromRecordBatches validity-bitmap validation to the other untrusted RecordBatch -> Table bridges, not just ArrowBlockInputFormat: ArrowFlightSource, ORCBlockInputFormat, and the DeltaLake table-changes reader. Otherwise an unknown FieldNode null_count over a truncated bitmap is still scanned out of bounds by FromRecordBatches before any ClickHouse validation runs. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…calar The bound-parameter RecordBatch in a Flight SQL prepared statement comes straight from the client (DoPut) and was passed to arrow::Array::GetScalar in buildQueryWithValues without validation. A malformed array (for example a one-row String whose offsets buffer is too small for the declared length) was read out of bounds inside GetScalar (heap-buffer-overflow in arrow::*::GetView). Fully validate the parameter batch buffers with arrow::RecordBatch::ValidateFull before extracting scalars, so a malformed batch is rejected with a clean INVALID_ARGUMENT instead of an OOB read. Adds an integration regression test that binds a malformed String parameter via a raw gRPC DoPut (pyarrow's high-level client validates batches client-side, so the malformed IPC bytes must be sent over a raw channel) and asserts the execute is rejected and the server stays alive. Verified the test fails (ASan heap-buffer-overflow) without the fix and passes with it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The empty-struct length cap rejected any fields-less (zero-field) Struct chunk that had no validity bitmap, which broke legitimate empty Tuple() round-trips through Arrow (03277_empty_tuple_formats, 03719_multiple_column_empty_tuple_formats). A non-nullable empty Tuple() is read as ColumnTuple::create(length), which only stores a row count and allocates nothing, so there is no DoS for the common case. The only allocation is the nullable wrapper's null map; for a fields-less struct its length has no backing buffer to validate against, so a forged huge length is left bounded by max_memory_usage (MEMORY_LIMIT_EXCEEDED), matching the null-type decision. The case where the struct carries a validity bitmap too small for the declared length is still rejected as INCORRECT_DATA by checkValidityBitmap. Drops the over-broad cap and the corresponding (no-bitmap) regression cases, keeping the bitmap-too-small case. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address review feedback that three fixtures did not prove the guard they target: - 04309 JSON data-buffer case: patch_last_i32 overwrote offset[0], producing offsets [huge, 96] (an out-of-bounds offset) instead of [0, huge]. Patch the final offset (offset[1]) so offset[0]=0 is valid and value_length overruns the data buffer, exercising the "safe_length > data_buf_size - safe_offset" half of the per-row guard. Verified the error is "row 0 has offset 0 and length 536870912 but buffer is 96 bytes". - 04307 dictionary-index case: inflate_row_count patched every int64=2, inflating the dictionary-values batch too, so the rejection could come from the values buffer. Use 3 dictionary values with 2 indices so inflate(2) only touches the index FieldNode/RecordBatch length; the values batch stays valid and the rejection comes from the index buffer (8 bytes available, 65536 required). - 04310 overflow case: assert INCORRECT_DATA instead of accepting any failure. checkArrowBuffer now validates the data buffer (via __builtin_mul_overflow) before the column reserve, so the file is rejected as "buffer size overflow" rather than CANNOT_ALLOCATE_MEMORY; the strict assertion proves the checked-arithmetic path. Dropped the now-unused check_rejected helper. Co-Authored-By: Claude Opus 4.8 <[email protected]>
readColumnWithUUIDFromFixedBinaryData validated the data buffer but reserved a sizeof(UUID)=16-bytes-per-row column before checking byte_width() == sizeof(UUID). A FixedSizeBinary(1) column read with a UUID type hint therefore reserved 16x the (attacker-controlled) row count and only afterwards threw on the width mismatch, leaving this reader in the reserve-before-validation class. Reject byte_width() != sizeof(UUID) up front, before the reserve, the same way readColumnWithBigIntegerFromFixedBinaryData checks fixed_len. The per-chunk width check (now redundant, since the type is uniform across chunks) is dropped. Regression: a FixedSizeBinary(1)-as-UUID case in 04330_arrow_oob_declared_length.sh, read under an 8 MB limit below the 16 MB reserve. Verified it throws INCORRECT_DATA with the fix and MEMORY_LIMIT_EXCEEDED without it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Move the per-row data-buffer bounds check ahead of the reserve in the JSON, BigNumber, and IPv6 binary readers, so valid offsets metadata over a truncated data buffer is rejected as INCORRECT_DATA before the allocation rather than after it. Also tighten the malformed prepared-statement parameter integration test to assert the specific Arrow offsets-buffer validation error instead of any exception. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Arrow IPC: fix heap out-of-bounds reads and structural validation gaps in the column reader
Resolve conflicts: drop the ArrowFlightServer ValidateFull hunk and the prepared-statement integration test because 26.4 has no ArrowFlight prepared-statement support, and keep the 26.4 variant of the read_as_nullable_column condition in ArrowColumnToCHColumn.
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.
Original pull-request #106395
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job