[#2095] node: Do not allow `GETRANGE` requests with zero length

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
carpawell/fix/multiple-cache-update-requests-FROST
Pavel Karpy 2022-11-24 17:28:50 +03:00 committed by Anton Nikiforov
parent d6196c3971
commit 350eecfa13
2 changed files with 30 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package getsvc
import (
"errors"
"hash"
coreclient "github.com/TrueCloudLab/frostfs-node/pkg/core/client"
@ -21,6 +22,30 @@ type RangePrm struct {
rng *object.Range
}
var (
errRangeZeroLength = errors.New("zero range length")
errRangeOverflow = errors.New("range overflow")
)
// Validate pre-validates `OBJECTRANGE` request's parameters content
// without access to the requested object's payload.
func (p RangePrm) Validate() error {
if p.rng != nil {
off := p.rng.GetOffset()
l := p.rng.GetLength()
if l == 0 {
return errRangeZeroLength
}
if off+l <= off {
return errRangeOverflow
}
}
return nil
}
// RangeHashPrm groups parameters of GetRange service call.
type RangeHashPrm struct {
commonPrm

View File

@ -229,6 +229,11 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
p.SetChunkWriter(streamWrapper)
p.SetRange(object.NewRangeFromV2(body.GetRange()))
err = p.Validate()
if err != nil {
return nil, fmt.Errorf("request params validation: %w", err)
}
if !commonPrm.LocalOnly() {
var onceResign sync.Once
var globalProgress int