feat(arrow/array): add Validate/ValidateFull to binary and string arrays#747
Open
zeroshade wants to merge 1 commit intoapache:mainfrom
Open
feat(arrow/array): add Validate/ValidateFull to binary and string arrays#747zeroshade wants to merge 1 commit intoapache:mainfrom
zeroshade wants to merge 1 commit intoapache:mainfrom
Conversation
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
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.
Summary
Fixes #691
Adds
Validate()andValidateFull()methods toBinary,LargeBinary,String, andLargeStringarray types, plus top-level dispatch functions and record-level convenience helpers.Problem
The existing
setDatavalidation 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 runtimepanic: slice bounds out of rangewhenValue(i)is called later, after the IPC reader'srecover()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 existingsetDatachecks, 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 caseValidate(arr arrow.Array) error/ValidateFull(arr arrow.Array) error— top-level dispatch via the newValidatorinterfaceValidateRecord(rec arrow.RecordBatch) error/ValidateRecordFull(...)— convenience wrappers that validate all columns, with error messages including column index and nameUsage
Test plan
TestBinaryValidate— valid arrays, sliced arrays, non-monotonic offsets, negative first offsetTestLargeBinaryValidate— same for large binaryTestStringValidate— same for stringTestLargeStringValidate— same for large stringTestTopLevelValidate— dispatch toValidator, passthrough for non-Validatortypes,ValidateRecordwith mixed valid/corrupt columns