From 32458baeb77546dab4806f1e852304a9225efec4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 17 Feb 2022 20:16:30 +0300 Subject: [PATCH] [#131] client: Fix false `io.ErrUnexpectedEOF` return in readers Signed-off-by: Leonard Lyubich --- client/object_get.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/object_get.go b/client/object_get.go index 0c68b18..55fe239 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -240,6 +240,9 @@ func (x *ObjectReader) Close() (*ResObjectGet, error) { // Read implements io.Reader of the object payload. func (x *ObjectReader) Read(p []byte) (int, error) { n, ok := x.readChunk(p) + + x.remainingPayloadLen -= n + if !ok { res, err := x.close(false) if err != nil { @@ -249,12 +252,10 @@ func (x *ObjectReader) Read(p []byte) (int, error) { return n, apistatus.ErrFromStatus(res.Status()) } - if n > x.remainingPayloadLen { + if x.remainingPayloadLen < 0 { return n, errors.New("payload size overflow") } - x.remainingPayloadLen -= n - return n, nil } @@ -615,6 +616,9 @@ func (x *ObjectRangeReader) Close() (*ResObjectRange, error) { // Read implements io.Reader of the object payload. func (x *ObjectRangeReader) Read(p []byte) (int, error) { n, ok := x.readChunk(p) + + x.remainingPayloadLen -= n + if !ok { res, err := x.close(false) if err != nil { @@ -624,12 +628,10 @@ func (x *ObjectRangeReader) Read(p []byte) (int, error) { return n, apistatus.ErrFromStatus(res.Status()) } - if n > x.remainingPayloadLen { + if x.remainingPayloadLen < 0 { return n, errors.New("payload range size overflow") } - x.remainingPayloadLen -= n - return n, nil }