Skip to content

fix(core): check start offset <= end offset#7340

Closed
dentiny wants to merge 8 commits intoapache:mainfrom
dentiny:hjiang/check-start-le-end-offset
Closed

fix(core): check start offset <= end offset#7340
dentiny wants to merge 8 commits intoapache:mainfrom
dentiny:hjiang/check-start-le-end-offset

Conversation

@dentiny
Copy link
Copy Markdown
Contributor

@dentiny dentiny commented Mar 31, 2026

Which issue does this PR close?

Closes #7337

Rationale for this change

Start offset <= end offset is the precondition that for any valid ranges, I found opendal panics when giving an invalid input range.

What changes are included in this PR?

This PR does check for all range inputs that I'm aware of, and return error (if possible) and assertion failure (if returning error is not easy).

Are there any user-facing changes?

No.

AI Usage Statement

The bug was found by opus 4.6 chaos test, and it figure out all the code pointers I need to update.

@dentiny dentiny requested a review from Xuanwo as a code owner March 31, 2026 04:01
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 31, 2026
@dentiny dentiny force-pushed the hjiang/check-start-le-end-offset branch 3 times, most recently from d90fae8 to 2b8a1ac Compare March 31, 2026 04:29
@dentiny dentiny force-pushed the hjiang/check-start-le-end-offset branch from 2b8a1ac to d88df34 Compare March 31, 2026 04:40
@dentiny dentiny requested a review from tisonkun as a code owner March 31, 2026 04:40
// <range-start>-<range-end>
let start: u64 = v[0].parse().map_err(parse_int_error)?;
let end: u64 = v[1].parse().map_err(parse_int_error)?;
if end < start {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we change the API of BytesRange too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I change From<T> into a Result<>-returned API from_range.

@dentiny dentiny requested a review from Xuanwo March 31, 2026 08:28
where
T: RangeBounds<u64>,
{
fn from(range: T) -> Self {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a super large change as many of our API depends on this.

And I also think we don't need to change this. Rust API is clear that "It is empty if start >= end."

We can follow the same pattern. Downstream caller can check and return empty results.

@dentiny
Copy link
Copy Markdown
Contributor Author

dentiny commented Apr 3, 2026

I will redo this PR later when I got some time, it's not a big issue.

@dentiny dentiny closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: range with end larger than start leads to underflow

2 participants