Skip to content

Commit

Permalink
[#131] client: Fix false io.ErrUnexpectedEOF return in readers
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Feb 18, 2022
1 parent 69fffac commit 32458ba
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions client/object_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 32458ba

Please sign in to comment.