Fix negative start offsets in FTP cat_file - #2196
Merged
martindurant merged 4 commits intoSep 29, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FTPFileSystem.cat_file(path, start=-3)currently sends a negative FTP restart offset whenendis omitted. A server can reject that offset, which fsspec reports asFileNotFoundErroreven 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.pypass 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 andgit diff --checkpass.