Skip to content

read_into ignores the byte range for single-fragment reads #25

Description

@eyupcanakman

Summary

read_into in lore-storage/src/read.rs takes an optional byte range, but for a single, non-fragmented fragment it ignores the range and copies the whole fragment. The caller's slice is sized to range.len(), so any partial read returns Err("unexpected size: slice N vs buffer M") (read.rs:560).

Files up to FRAGMENT_SIZE_THRESHOLD (256 KiB) are stored as one fragment, and the swfs/projfs read handlers call read_into with Some(offset..offset + len). So reading a small file at any non-zero offset fails. The read() function in the same file applies the range correctly with buffer.slice(range) (read.rs:459), as does the fragmented branch; only the single-fragment branches of read_into drop it.

Steps to reproduce

// 100-byte fragment, read bytes 10..50
let mut out = [0u8; 40];
read_into(store, partition, addr, Some(10..50), &mut out, opts, None).await;
// expected: Ok(()), out == content[10..50]
// actual:   Err("unexpected size: slice 40 vs buffer 100")

I have a fix (apply range in both single-fragment branches, the way read() already does) plus a regression test. Happy to open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions