diff/apply.readCounter: check negative size#7494
Merged
fuweid merged 1 commit intocontainerd:mainfrom Oct 10, 2022
Merged
Conversation
`rc.r.Read()` may return a negative `int` on an error when the reader is set to a custom content store implementation Signed-off-by: Akihiro Suda <[email protected]>
akhilerm
reviewed
Oct 10, 2022
| func (rc *readCounter) Read(p []byte) (n int, err error) { | ||
| n, err = rc.r.Read(p) | ||
| rc.c += int64(n) | ||
| if n > 0 { |
Member
There was a problem hiding this comment.
question: If the rc.r.Read(p) returns an error, the value of n should not matter right?, as readCounter.Read() will also be returning an error which the caller should recognise.
Member
Author
There was a problem hiding this comment.
If the rc.r.Read(p) returns an error, the value of n should not matter right?
Matters, IIUC
https://pkg.go.dev/io#Reader
When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read.
akhilerm
approved these changes
Oct 10, 2022
samuelkarp
approved these changes
Oct 10, 2022
fuweid
approved these changes
Oct 10, 2022
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.
rc.r.Read()may return a negativeinton an error when the reader is set to a custom content store implementation