Skip to content

lore-storage: Make read_into respect the byte range for single-fragment reads - #37

Closed
itsfuad wants to merge 1 commit into
EpicGames:mainfrom
itsfuad:main
Closed

lore-storage: Make read_into respect the byte range for single-fragment reads#37
itsfuad wants to merge 1 commit into
EpicGames:mainfrom
itsfuad:main

Conversation

@itsfuad

@itsfuad itsfuad commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What:
Make read_into respect the byte range for single-fragment reads in lore-storage.

Why:
read_into accepts an optional byte range, but both single-fragment branches (compressed and uncompressed) were comparing slice.len() against the full fragment payload instead of the requested range. Any partial read on a file ≤ 256 KiB (the FRAGMENT_SIZE_THRESHOLD) would fail with unexpected size: slice 40 vs buffer 100. The fragmented branch and the sibling read() both handle this correctly, only read_into's single-fragment paths were missing it.

Fixes #25

How:
Added one line to each single-fragment branch to slice the buffer to the requested range before the existing size check and copy:

// compressed
let decompressed = decompressed.freeze().slice(range);

// uncompressed
let buffer = buffer.slice(range);

Testing:
Added a regression test that stores a 100-byte fragment and reads bytes 10..50 into a 40-byte buffer, reproducing the original failure.

@rajpratham1 rajpratham1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a focused bug fix that addresses a clear inconsistency in read_into. The change is minimal, aligns the single-fragment paths with the existing fragmented implementation and read(), and includes a regression test that reproduces the original issue. I don't see any blocking concerns.

@mjansson mjansson changed the title fix(storage): read_into ignores the byte range for single-fragment reads lore-storage: Make read_into respect the byte range for single-fragment reads Jun 22, 2026
@mjansson

Copy link
Copy Markdown
Collaborator

Looks good - make sure you follow the guidelines at https://github.com/EpicGames/lore/blob/main/CONTRIBUTING.md#dco-sign-off and do the DCO signoff on the commits to let us take this in.

@itsfuad

itsfuad commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Looks good - make sure you follow the guidelines at https://github.com/EpicGames/lore/blob/main/CONTRIBUTING.md#dco-sign-off and do the DCO signoff on the commits to let us take this in.

@mjansson Done. Review please.

Fixes EpicGames#25. The two single-fragment branches (compressed and uncompressed)
in read_into now apply buffer.slice(range) before copying into the output
slice, matching what read() already does.

Added a regression test that stores a 100-byte fragment and reads bytes
10..50 into a 40-byte buffer.

Signed-off-by: Fuad Hasan <fuad.cs22@gmail.com>
@itsfuad

itsfuad commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@mjansson Fixed clippy issues in workflow run.

@mjansson

mjansson commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

We'll get this merged once the intake and attribution process is in place, ideally early next week.

@mjansson mjansson added the ready-to-import Approved by Epic staff for import into Lore label Jul 28, 2026
@epic-lore-bot epic-lore-bot Bot added imported Imported into Lore for internal review and removed ready-to-import Approved by Epic staff for import into Lore labels Jul 28, 2026
@epic-lore-bot

epic-lore-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

Imported as Lore CR-255.

epic-lore-bot Bot pushed a commit that referenced this pull request Jul 29, 2026
…nt reads

**What:**
Make `read_into` respect the byte range for single-fragment reads in `lore-storage`.

**Why:**
`read_into` accepts an optional byte `range`, but both single-fragment branches (compressed and uncompressed) were comparing `slice.len()` against the full fragment payload instead of the requested range. Any partial read on a file ≤ 256 KiB (the `FRAGMENT_SIZE_THRESHOLD`) would fail with `unexpected size: slice 40 vs buffer 100`. The fragmented branch and the sibling `read()` both handle this correctly, only `read_into`'s single-fragment paths were missing it.

Fixes #25

**How:**
Added one line to each single-fragment branch to slice the buffer to the requested range before the existing size check and copy:

```rust
// compressed
let decompressed = decompressed.freeze().slice(range);

// uncompressed
let buffer = buffer.slice(range);
```

**Testing:**
Added a regression test that stores a 100-byte fragment and reads bytes 10..50 into a 40-byte buffer, reproducing the original failure.

```
Imported-PR: #37
Imported-From: e7f0159
Imported-Base: c920a7f
Imported-Merge: d7ec30c
Imported-Author: Fuad Hasan (itsfuad)
Signed-off-by: Fuad Hasan <fuad.cs22@gmail.com>
GH-URL: #37
```

Lore-RevId: 369
Lore-Signature: ff073a1673a5c82adf7670ab0e3c09c4758c93364ee5d9ab6b9ff64fdcd5a64b
@epic-lore-bot

epic-lore-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Closed by mirrored commit e4202e7.

@epic-lore-bot epic-lore-bot Bot closed this Jul 29, 2026
@epic-lore-bot epic-lore-bot Bot added the merged Merged into Lore codebase label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imported Imported into Lore for internal review merged Merged into Lore codebase

Development

Successfully merging this pull request may close these issues.

read_into ignores the byte range for single-fragment reads

4 participants