Skip to content

diff/apply.readCounter: check negative size#7494

Merged
fuweid merged 1 commit intocontainerd:mainfrom
AkihiroSuda:diff-apply-fix-read-count
Oct 10, 2022
Merged

diff/apply.readCounter: check negative size#7494
fuweid merged 1 commit intocontainerd:mainfrom
AkihiroSuda:diff-apply-fix-read-count

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

rc.r.Read() may return a negative int on an error when the reader is set to a custom content store implementation

`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]>
Comment thread diff/apply/apply.go
func (rc *readCounter) Read(p []byte) (n int, err error) {
n, err = rc.r.Read(p)
rc.c += int64(n)
if n > 0 {
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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

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.

Thank you

@fuweid fuweid merged commit 7f33a20 into containerd:main Oct 10, 2022
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.

4 participants