diff/apply.readCounter: check negative size

`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 <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2022-10-08 10:17:35 +09:00
parent 4a0ddfa974
commit 39158629f7
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A

View File

@ -125,6 +125,8 @@ type readCounter struct {
func (rc *readCounter) Read(p []byte) (n int, err error) {
n, err = rc.r.Read(p)
rc.c += int64(n)
if n > 0 {
rc.c += int64(n)
}
return
}