Repository navigation
MINOR: [C++] Reject negative array offset in ArrayData validation - #53953
Closed
Nayana-Naik73 wants to merge 1 commit into
Closed
Nayana-Naik73 wants to merge 1 commit into
Nayana-Naik73 wants to merge 1 commit into
Conversation
|
Thanks for opening a pull request! This pull request has been automatically closed because you currently have 4 open pull requests, which is more than the limit of 3. Due to the increase in pull requests opened by AI bots, and in order to keep the review queue manageable, Apache Arrow limits contributors without repository access to at most 3 concurrently open pull requests. This helps make sure each pull request gets the attention it needs and that work in progress does not go stale. Once one of your other open pull requests has been merged or closed, you are welcome to reopen this one. See also: |
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.
Rationale for this change
ValidateArrayImpl::ValidateLayoutrejects a negative array length but never checks the offset. Every minimum buffer-size check below it is computed fromlength + offset, so a negative offset that cancels the length drives that sum to 0 and lets zero-sized or too-small buffers pass validation.A negative offset reaches
ArrayDatathrough the C Data Interface:ArrayImportercopies the producer-suppliedoffsetstraight into the array and derives each buffer's expected size aslength + offset.ValidateFull()is the documented way for a consumer to vet an imported array from an untrusted producer. Withoffset = -lengthand a short values buffer,Validate()andValidateFull()both return OK, and reading the array afterwards addresses before the buffer:raw_values_[offset + i]withoffset = -1000lands far outside the allocation (an out-of-bounds read, confirmed under ASan).What changes are included in this PR?
Add an
offset < 0check next to the existinglength < 0check inValidateLayout. Because validation recurses into child data, the single check covers every array and child.Are these changes tested?
Yes. A negative-offset case is added to the
ValidateBuffersPrimitivetest. It fails on the current tree (Validate()returns OK) and passes with the fix; both the fix and the test were exercised under an ASan/UBSan build with the fullarrow-array-testsuite green.Are there any user-facing changes?
Array::Validate()andArray::ValidateFull()now returnStatus::Invalidfor an array whose offset is negative. No valid array produces a negative offset, so valid inputs are unaffected.