Do not return io.EOF when n == len(p) #43
Merged
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.
io.ReaderAt docs says[1]:
We chose to return EOF, and this confuses io.CopyBuffer, since it expects to get io.EOF, not an error wrapping io.EOF[2]:
We can fix this by never wrapping io.EOF, or by not returning io.EOF when we can avoid it. I chose the second way since it is much simpler.
Fixed by returning EOF only if n < len(p) when reading zeros. This means that reading the last buffer will return len(p), nil, and trying to read the next buffer will return 0, EOF.
To reproduce we need to write zero cluster at the end of the image:
Without the fix we fail when reading the last 32k at 1015808:
I don't understand why we try to read with a buffer size of 32k, when we use a 64k buffer in the read example. This may be another bug.
[1] https://pkg.go.dev/io#ReaderAt
[2] https://cs.opensource.google/go/go/+/refs/tags/go1.23.2:src/io/io.go;l=449
Fixes: #40