Skip to content

fix: avoid panic when range starts past object end#61

Merged
shikhar merged 4 commits intomainfrom
gh54
Feb 1, 2026
Merged

fix: avoid panic when range starts past object end#61
shikhar merged 4 commits intomainfrom
gh54

Conversation

@shikhar
Copy link
Member

@shikhar shikhar commented Jan 31, 2026

Summary

  • guard page slicing when range starts beyond object end
  • return RangeNotSatisfied instead of panicking
  • add unit test covering out-of-bounds start within last page

Testing

  • cargo +nightly fmt
  • cargo clippy --all-features --all-targets -- -D warnings --allow deprecated
  • cargo nextest run

Closes #54

@greptile-apps
Copy link

greptile-apps bot commented Jan 31, 2026

Greptile Overview

Greptile Summary

Refactored page slicing logic to properly handle out-of-bounds range requests instead of panicking.

  • Extracted inline slicing code into dedicated slice_page_data function
  • Added bounds check: returns RangeNotSatisfied error when range start exceeds page data length
  • Changed stream combinator from map_ok to and_then to propagate errors
  • Added unit test slice_page_data_rejects_range_start_past_object_end covering the edge case

The fix follows Rust best practices from CLAUDE.md by using explicit error handling with Result<T, E> instead of allowing panics on out-of-bounds slice operations.

Confidence Score: 5/5

  • Safe to merge - critical bug fix with proper error handling and test coverage
  • Addresses a panic scenario with idiomatic Rust error handling, includes comprehensive unit test, follows project style guide, and maintains existing behavior for valid ranges
  • No files require special attention

Important Files Changed

Filename Overview
src/service/mod.rs extracted panic-prone slicing logic into slice_page_data with bounds checking, added test coverage

Sequence Diagram

sequenceDiagram
    participant Client
    participant CacheyService
    participant Stream
    participant slice_page_data
    participant Cache

    Client->>CacheyService: get(range)
    CacheyService->>Stream: iter pages in range
    loop for each page
        Stream->>Cache: fetch page
        Cache-->>Stream: (page_id, value)
        Stream->>slice_page_data: validate & slice(page_id, range, value)
        alt start_offset >= data_len
            slice_page_data-->>Stream: RangeNotSatisfied error
            Stream-->>Client: 416 Range Not Satisfiable
        else valid range
            slice_page_data-->>Stream: (sliced_data, range)
            Stream-->>Client: Chunk
        end
    end
Loading

@shikhar shikhar force-pushed the gh54 branch 2 times, most recently from 4be9150 to 6bf79f6 Compare February 1, 2026 00:31
@shikhar shikhar merged commit 9a6ff74 into main Feb 1, 2026
4 checks passed
@shikhar shikhar deleted the gh54 branch February 1, 2026 16:20
@github-actions github-actions bot mentioned this pull request Feb 1, 2026
shikhar pushed a commit that referenced this pull request Feb 1, 2026
## 🤖 New release

* `cachey`: 0.9.1 -> 0.9.2

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.9.2](0.9.1...0.9.2)
- 2026-02-01

### Fixed

- avoid panic when range starts past object end
([#61](#61))
- *(downloader)* keep hedge alive through body download
([#65](#65))
- make Prometheus metrics registry opt-in
([#64](#64))
- validate ObjectKind/ObjectKey during deserialization
([#62](#62))

### Other

- remove manual release commands from Justfile
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Panic on out-of-bounds range slicing when range starts past object end within final page

1 participant