forked from TrueCloudLab/frostfs-node
[#2095] node: Do not allow GETRANGE
requests with zero length
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
d6196c3971
commit
350eecfa13
2 changed files with 30 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package getsvc
|
package getsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"hash"
|
"hash"
|
||||||
|
|
||||||
coreclient "github.com/TrueCloudLab/frostfs-node/pkg/core/client"
|
coreclient "github.com/TrueCloudLab/frostfs-node/pkg/core/client"
|
||||||
|
@ -21,6 +22,30 @@ type RangePrm struct {
|
||||||
rng *object.Range
|
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.
|
// RangeHashPrm groups parameters of GetRange service call.
|
||||||
type RangeHashPrm struct {
|
type RangeHashPrm struct {
|
||||||
commonPrm
|
commonPrm
|
||||||
|
|
|
@ -229,6 +229,11 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
||||||
p.SetChunkWriter(streamWrapper)
|
p.SetChunkWriter(streamWrapper)
|
||||||
p.SetRange(object.NewRangeFromV2(body.GetRange()))
|
p.SetRange(object.NewRangeFromV2(body.GetRange()))
|
||||||
|
|
||||||
|
err = p.Validate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("request params validation: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if !commonPrm.LocalOnly() {
|
if !commonPrm.LocalOnly() {
|
||||||
var onceResign sync.Once
|
var onceResign sync.Once
|
||||||
var globalProgress int
|
var globalProgress int
|
||||||
|
|
Loading…
Reference in a new issue