Skip to content

bug: Integer underflow risk in reader fetch partition_point #6782

@rich7420

Description

@rich7420

Describe the bug

The fetch method uses partition_point to find the corresponding merged range, but doesn't check if partition_point returns 0. When partition_point returns 0, 0 - 1 causes integer underflow (becomes usize::MAX), leading to out-of-bounds access and panic.

let idx = merged_ranges.partition_point(|v| v.start <= range.start) - 1;

Steps to Reproduce

none

Expected Behavior

Check if partition_point returns 0 before subtracting 1, and validate that each range is within the merged ranges.

Additional Context

No response

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleases-note/fixThe PR fixes a bug or has a title that begins with "fix"rustPull requests that update Rust code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions