[#131] client: Fix false io.ErrUnexpectedEOF return in readers

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-02-17 20:16:30 +03:00 committed by LeL
parent 69ffface78
commit 32458baeb7

View file

@ -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
}