Skip to content

Fix negative start offsets in FTP cat_file - #2196

Merged
martindurant merged 4 commits into
fsspec:masterfrom
rioyu123:codex/ftp-negative-read-offsets
Sep 29, 2026
Merged

martindurant merged 4 commits into
fsspec:masterfrom
rioyu123:codex/ftp-negative-read-offsets

Conversation

@rioyu123

@rioyu123 rioyu123 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

FTPFileSystem.cat_file(path, start=-3) currently sends a negative FTP restart offset when end is omitted. A server can reject that offset, which fsspec reports as FileNotFoundError even when the file exists.

Route negative starts through the existing buffered range-reading path, which resolves them against the file size and clamps to zero. Positive starts, full-file reads and calls with an explicit end are unchanged.

Add real local FTP regressions for negative, zero and positive starts, negative offsets larger than the file length, an explicit end, empty files and missing files. Follow-up tests also preserve full and positive-offset reads after another FTP connection grows a file whose size was already cached. Using the inherited implementation for those reads would truncate them to the cached size, so the direct EOF-read path is retained.

Validation: four original regression cases fail on the unchanged base commit; all 33 tests in test_ftp.py pass against a local pyftpdlib server with the fix (CPython 3.13, Windows). Both new cached-size cases fail when the FTP override is replaced with the inherited implementation, and pass with the direct path. Changed-file Ruff 0.14.3 checks and git diff --check pass.

Comment thread fsspec/implementations/ftp.py
@martindurant
martindurant merged commit 4c19cfc into fsspec:master Sep 29, 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