From 39158629f7b7913e14b94409bf205ee8be965254 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sat, 8 Oct 2022 10:17:35 +0900 Subject: [PATCH] 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 --- diff/apply/apply.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diff/apply/apply.go b/diff/apply/apply.go index d4b34238c..814bbe336 100644 --- a/diff/apply/apply.go +++ b/diff/apply/apply.go @@ -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 }