Skip to content

Return an empty read_block when the offset is past EOF - #2261

Merged
martindurant merged 2 commits into
fsspec:masterfrom
adenzhou1350:codex/read-block-past-eof
Oct 14, 2026
Merged

martindurant merged 2 commits into
fsspec:masterfrom
adenzhou1350:codex/read-block-past-eof

Conversation

@adenzhou1350

Copy link
Copy Markdown
Contributor

Reading a block beyond EOF can turn the requested length into a negative number. For example, fs.read_block(path, 5, 1) on a three-byte local file passes -2 to the file's read() and raises ValueError, whereas the memory backend returns an empty block. The same problem affects length=None and delimiter reads.

Clamp the remaining length to zero. Reads within the file and delimiter alignment remain unchanged. Add local/memory regression cases for in-file, EOF, one-byte-past and two-byte-past offsets, with finite/None lengths and with/without a delimiter.

Validation against master 94afb3f6:

  • Unmodified source: 4 failures / 28 passing controls on both Windows and Linux Python 3.12.
  • Fixed: Windows utility module 165 passed; Linux utility, filesystem-spec, local and memory modules 781 passed, 28 skipped, 1 existing xfail. One existing multithreaded-fork deprecation warning remains.
  • Repository-pinned Ruff 0.14.3 check/format and diff check pass.

This is distinct from #2256's split_before handling and does not alter that utility branch. AI-assisted, independently reproduced with actual local files and the public filesystem API. No cloud-service or full-CI qualification is claimed.

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
@martindurant
martindurant merged commit c59cd07 into fsspec:master Oct 14, 2026
11 checks passed
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.

2 participants