Skip to content

feat(arrow/array): add Validate/ValidateFull to binary and string arrays#747

Open
zeroshade wants to merge 1 commit intoapache:mainfrom
zeroshade:buffer-validation
Open

feat(arrow/array): add Validate/ValidateFull to binary and string arrays#747
zeroshade wants to merge 1 commit intoapache:mainfrom
zeroshade:buffer-validation

Conversation

@zeroshade
Copy link
Copy Markdown
Member

Summary

Fixes #691

Adds Validate() and ValidateFull() methods to Binary, LargeBinary, String, and LargeString array types, plus top-level dispatch functions and record-level convenience helpers.

Problem

The existing setData validation only checks the last offset against the data buffer length. Subtly corrupted data — e.g. non-monotonic or negative intermediate offsets — passes construction but causes a runtime panic: slice bounds out of range when Value(i) is called later, after the IPC reader's recover() scope has already returned. Users receiving data from untrusted sources (e.g. Flight SQL from Doris DB) have no way to detect this without crashing.

Solution

  • Validate() — O(1): checks offset buffer size and that the last offset is within the data buffer (mirrors existing setData checks, but returns an error instead of panicking)
  • ValidateFull() — O(n): additionally verifies all offsets are non-negative and monotonically non-decreasing, catching the subtle corruption case
  • Validate(arr arrow.Array) error / ValidateFull(arr arrow.Array) error — top-level dispatch via the new Validator interface
  • ValidateRecord(rec arrow.RecordBatch) error / ValidateRecordFull(...) — convenience wrappers that validate all columns, with error messages including column index and name

Usage

rec, err := reader.Read()
if err != nil { ... }
if err := array.ValidateRecordFull(rec); err != nil {
    log.Printf("skipping corrupted batch: %v", err)
    rec.Release()
    continue
}

Test plan

  • TestBinaryValidate — valid arrays, sliced arrays, non-monotonic offsets, negative first offset
  • TestLargeBinaryValidate — same for large binary
  • TestStringValidate — same for string
  • TestLargeStringValidate — same for large string
  • TestTopLevelValidate — dispatch to Validator, passthrough for non-Validator types, ValidateRecord with mixed valid/corrupt columns

Adds Validate() and ValidateFull() methods to Binary, LargeBinary, String,
and LargeString array types, plus top-level Validate/ValidateFull dispatch
functions and ValidateRecord/ValidateRecordFull convenience helpers.

The existing setData check only verifies the last offset is within the data
buffer. Subtly corrupted data (e.g. non-monotonic or negative intermediate
offsets) passes construction but causes runtime panics when Value() is called
later, after the IPC reader's recover() scope has ended.

ValidateFull() catches these cases by checking all offsets are non-negative
and monotonically non-decreasing. This allows users receiving data from
untrusted sources such as Flight SQL servers to detect and skip corrupted
batches rather than crashing.

Fixes apache#691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve robustness against corrupted Arrow buffers from Flight SQL

1 participant