Skip to content

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

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

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

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
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
Author

@mjansson Fixed clippy issues in workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

read_into ignores the byte range for single-fragment reads

4 participants