bugfix(corelib): Fixed ByteSpan::get OOB empty range. - #10051
Conversation
PR SummaryLow Risk Overview This matches the existing docs (“out of bounds: returns Reviewed by Cursor Bugbot for commit 1a61329. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

Summary
ByteSpan::getwith a range wherestart == endpreviously always returnedSome(Default::default())(an empty slice), even when the range was entirely out of bounds. It now returnsNonewhenrange.start > self.len().Type of change
Please check one:
Why is this change needed?
An empty range (
start == end) that falls beyond the end of the span was silently returning a valid empty slice instead of signaling that the index is out of bounds. This is inconsistent with how non-empty out-of-bounds ranges are handled (they returnNone) and with the general contract thatgetreturnsNonefor invalid indices.What was the behavior or documentation before?
span.get(n..n)returnedSome("")for any value ofn, regardless of whethernwas within the bounds of the span.What is the behavior or documentation after?
span.get(n..n)returnsSome("")only whenn <= span.len(), and returnsNonewhenn > span.len(), matching the behavior of out-of-bounds non-empty range queries.Related issue or discussion (if any)
Additional context
Tests were added for out-of-bounds empty-range queries on spans of various lengths (including spans backed by 30-byte and 31-byte
ByteArrays) to cover the boundary conditions around word alignment.