Skip to content

Conversation

@shikhar
Copy link
Member

@shikhar shikhar commented Jan 21, 2026

Fixes #44

@shikhar shikhar marked this pull request as ready for review January 21, 2026 03:11
@greptile-apps
Copy link

greptile-apps bot commented Jan 21, 2026

Greptile Summary

This PR fixes a panic that occurred when clients requested byte ranges exceeding the actual object size. When streaming cached pages, the code calculates slice offsets for the last page based on the requested range. If the request extends past the object boundary (e.g., requesting 24MB from a 20MB object), the calculated end_offset would exceed value.data.len(), causing Bytes::slice() to panic.

The fix clamps end_offset using .min(end_offset) (where end_offset was initialized to the actual data length) and updates range_end to reflect the bytes actually returned. This prevents the panic and ensures the response range is consistent with the data served.

Confidence Score: 5/5

  • This PR is safe to merge - it's a targeted two-line fix that prevents a panic without changing normal behavior.
  • The fix is minimal, correct, and follows the recommended approach from the bug report. It clamps values to prevent out-of-bounds access and keeps the reported range consistent with actual data. No new edge cases are introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
src/service/mod.rs Fixed panic when requested byte range exceeds object size by clamping end_offset to actual data length and updating range_end to reflect actual bytes returned.

Sequence Diagram

sequenceDiagram
    participant Client
    participant CacheyService
    participant PageGetExecutor
    participant Cache

    Client->>CacheyService: GET /fetch/{kind}/{object} (Range: 0-24MB)
    Note over CacheyService: Object is only 20MB (spans 2 pages)
    CacheyService->>CacheyService: Calculate page bounds (page 0, page 1)
    
    loop For each page (buffered)
        CacheyService->>PageGetExecutor: execute(page_id)
        PageGetExecutor->>Cache: get_or_fetch(cache_key)
        Cache-->>PageGetExecutor: CacheValue (with actual data)
        PageGetExecutor-->>CacheyService: (page_id, value)
    end
    
    Note over CacheyService: Page 0: full 16MB page
    CacheyService->>CacheyService: slice(0..16MB) ✓
    
    Note over CacheyService: Page 1: only 4MB of data
    CacheyService->>CacheyService: end_offset = min(7.2MB, 4MB) = 4MB
    CacheyService->>CacheyService: slice(0..4MB) ✓ (was panic before fix)
    
    CacheyService-->>Client: Stream chunks with correct range
Loading

@shikhar shikhar merged commit dc5693d into main Jan 21, 2026
5 checks passed
@shikhar shikhar deleted the gh44 branch January 21, 2026 03:13
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 when requested byte range exceeds object size (last-page slice overruns)

2 participants