Repository navigation
operations: fix cat --offset before the start of a file printing its end - #10216
Merged
Merged
Conversation
When a negative --offset reached back past the start of a file and
--count was set, rclone cat printed bytes from the end of the file
instead of from its start. For example on a 10 byte file
rclone cat --offset -12 --count 5 file
printed the last 2 bytes rather than the first 5. With several files
of different sizes, each file shorter than -offset was affected.
The start of the range stayed negative after the file size was added,
and a negative Start with an End set is a suffix range (the last End
bytes). Clamp the start to 0 instead, which matches what
`tail -c 12 file | head -c 5` prints. --tail and --offset without
--count were not affected.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What does this change do?
rclone catwith a negative--offsetthat reaches back past the start of a file, combined with--count, prints bytes from the end of the file instead of from its start. On a 10 byte file:The expected output is
ABCDE, which is whattail -c 12 file1.txt | head -c 5prints. When catting a directory, every file shorter than the offset is affected: for a 10 byte and a 9 byte file,rclone cat --offset -12 --count 5 dirprintedIJ8instead ofABCDE01234.catObjectadds the object size to a negative offset, but when the offset is larger than the file the start stays negative. ARangeOptionwith a negativeStartand anEndset is a suffix range (the lastEndbytes), so the wrong part of the file is read. This clamps the start to 0.--tail, and--offsetwithout--count, behave as before. The same function backs the rcoperations/catcall.I added two cases to
TestCat; both fail without the change.Linked issue
None, it's a small bug fix.
Checklist
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.I used Claude Code to write this change.