fix: validate union child bounds without truncating lengths - #10847
Draft
sunchao wants to merge 1 commit into
Draft
fix: validate union child bounds without truncating lengths#10847sunchao wants to merge 1 commit into
sunchao wants to merge 1 commit into
Conversation
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.
Why are the changes needed?
Which issue does this PR close?
Closes #10845.
Rationale for this change
A dense Union can have a child longer than
i32::MAXwhile referencing only validi32offsets.UnionArray::try_newtruncates child lengths toi32, so the length can collide with its missing-type sentinel or fail the bounds check. ANullArrayreproduces this without a large allocation.What changes were proposed in this PR?
What changes are included in this PR?
Keep child lengths as
Option<usize>, separating a missing type ID from a valid length. Reject negative offsets before converting them tousizefor comparison. Add coverage for lengthsi32::MAX + 1andi32::MAX + 2, offsets zero andi32::MAX, and invalid negative offsets.Are there any user-facing changes?
Previously rejected valid Unions are accepted. Invalid type IDs and out-of-bounds offsets still return errors. No public API changes.
How was this PR tested?
Are these changes tested?
cargo test --offline -p arrow-array --lib: 719 passed, 1 ignored.cargo clippy --offline -p arrow-array --all-targets --all-features -- -D warnings: passed.cargo fmt --all -- --check: passed.AI assistance: Codex generated the implementation, regression tests, and PR text, and performed the stated local checks and source review. This does not claim a separate human review.