Conversation
`into_arrow_offset_buffer` is a safe function, but it called
`OffsetBuffer::new_unchecked` and pushed the memory-safety requirement onto the caller in
a doc comment:
/// SAFETY: The caller should ensure that the buffer contains monotonically increasing
/// values greater than or equal to zero.
A safe function may not carry unchecked memory-safety preconditions. `OffsetBuffer`
requires its contents to be non-empty, to start at a non-negative value and to be
monotonically non-decreasing; safe code that violates those invariants causes
out-of-bounds reads in downstream Arrow operations such as slicing and child-array
indexing.
Use the checked `OffsetBuffer::new` instead. It validates the offsets and panics on bad
input, which is memory-safe. The signature is unchanged, so callers are unaffected.
Signed-off-by: Jian He <hejia@google.com>
robert3005
reviewed
Oct 5, 2026
| /// | ||
| /// Panics if the buffer is empty, its first offset is negative, or it is not monotonically | ||
| /// increasing -- the invariants `OffsetBuffer` requires of its contents. | ||
| pub fn into_arrow_offset_buffer(self) -> OffsetBuffer<T> { |
Contributor
There was a problem hiding this comment.
I think we have to adjust the callers to not have to perform revalidation. In general this should perform validation but most of the callers already validated it
This branch has not been deployed
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.
into_arrow_offset_bufferis a safe function, but it calledOffsetBuffer::new_uncheckedand left the invariants to a doc comment ("SAFETY: The caller should ensure..."). A safe function can't carry unchecked memory-safety preconditions.OffsetBufferrequires non-empty, non-negative-first, monotonically non-decreasing offsets, and breaking that from safe code leads to out-of-bounds reads in downstream Arrow slicing and child indexing.This switches to the checked
OffsetBuffer::new, which panics on invalid input. The signature is unchanged.Cost:
OffsetBuffer::newdoes an O(n) validation pass. The callers are invortex-arrow(executor/byte.rs,executor/list.rs). If that cost matters on those paths, the alternative is to makeinto_arrow_offset_bufferanunsafe fnwith a# Safetysection and keepnew_unchecked. Happy to switch to that.Testing
cargo test -p vortex-buffer --all-features,cargo test -p vortex-arrow --all-features, clippy, nightly fmt.AI assistance
This change was prepared with help from an AI coding assistant (Google-internal agentic tooling). I reviewed and verified the change and the tests myself.