Skip to content

lib/readers: return the cache length when RepeatableReader.Seek goes past it - #10149

Merged
ncw merged 1 commit into
rclone:masterfrom
kevin9327:fix-repeatable-seek-unavailable-offset
Oct 29, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
kevin9327:fix-repeatable-seek-unavailable-offset

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

RepeatableReader.Seek is documented to return the maximum usable offset (the length of the cached data) together with the "offset is unavailable" error when asked to seek past the cache. It returned offset - (abs - cacheLen) instead, which only equals cacheLen for io.SeekStart. With io.SeekCurrent from a non-zero position, or with io.SeekEnd, it returned an unrelated number. For example, after reading 10 bytes and seeking back to 8, Seek(5, io.SeekCurrent) returned 2 and Seek(5, io.SeekEnd) returned 0. A large offset could even make it negative.

The fix returns cacheLen in that branch. The read position is still left unchanged.

Was the change discussed in an issue or in the forum before?

No. I found it while reading the code.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

TestRepeatableReaderSeekUnavailableReturnsCacheLength fails before the fix (it gets 2 and 0, expects 10) and passes after. go test ./lib/readers/ passes.

AI assistance: I used an AI coding assistant to help find and write this change. I reviewed the code and test and ran them myself.

…past it

Seek documents that a position past the cached data returns the maximum
usable offset with an error, but it returned offset - (abs - cacheLen),
which is only the cache length for io.SeekStart. For io.SeekCurrent and
io.SeekEnd it returned an arbitrary, possibly negative, number.
@kevin9327
kevin9327 requested a review from ncw as a code owner October 20, 2026 12:21

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix :-)

@ncw
ncw merged commit 337c130 into rclone:master Oct 29, 2026
9 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