Repository navigation
lib/readers: return the cache length when RepeatableReader.Seek goes past it - #10149
Merged
ncw merged 1 commit intoOct 29, 2026
Merged
Conversation
…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.
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 is the purpose of this change?
RepeatableReader.Seekis 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 returnedoffset - (abs - cacheLen)instead, which only equalscacheLenforio.SeekStart. Withio.SeekCurrentfrom a non-zero position, or withio.SeekEnd, it returned an unrelated number. For example, after reading 10 bytes and seeking back to 8,Seek(5, io.SeekCurrent)returned 2 andSeek(5, io.SeekEnd)returned 0. A large offset could even make it negative.The fix returns
cacheLenin 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
TestRepeatableReaderSeekUnavailableReturnsCacheLengthfails 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.