mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(shardnode): check request blob name length
with #22357426 Signed-off-by: xiejian <xiejian3@oppo.com>
This commit is contained in:
parent
80e0ac3b81
commit
ba801c5c77
@ -163,6 +163,8 @@ var errCodeMap = map[int]string{
|
||||
CodeIllegalSlices: "shardnode:alloc with illegal slices",
|
||||
CodeBlobAlreadyExists: "shardnode:blob already exists",
|
||||
CodeShardConflicts: "shardnode:shard conflicts",
|
||||
CodeKeySizeTooLarge: "shardnode:key size large than 32KB",
|
||||
CodeValueSizeTooLarge: "shardnode:value size large than 16MB",
|
||||
}
|
||||
|
||||
// HTTPError make rpc.HTTPError
|
||||
|
||||
@ -26,19 +26,23 @@ const (
|
||||
CodeBlobAlreadyExists = 1009
|
||||
CodeUnsupport = 1010
|
||||
CodeShardConflicts = 1011
|
||||
CodeKeySizeTooLarge = 1012
|
||||
CodeValueSizeTooLarge = 1013
|
||||
)
|
||||
|
||||
// 10xx
|
||||
var (
|
||||
ErrShardNodeNotLeader = newError(CodeShardNodeNotLeader, "shard node is not leader")
|
||||
ErrShardRangeMismatch = newError(CodeShardRangeMismatch, "shard range mismatch")
|
||||
ErrShardDoesNotExist = newError(CodeShardDoesNotExist, "shard doest not exist")
|
||||
ErrShardNodeDiskNotFound = newError(CodeShardNodeDiskNotFound, "shard disk not found")
|
||||
ErrUnknownField = newError(CodeUnknownField, "unknown field")
|
||||
ErrShardRouteVersionNeedUpdate = newError(CodeShardRouteVersionNeedUpdate, "shard route version need update")
|
||||
ErrShardNoLeader = newError(CodeShardNoLeader, "shard has no leader")
|
||||
ErrIllegalSlices = newError(CodeIllegalSlices, "illegal slices")
|
||||
ErrBlobAlreadyExists = newError(CodeBlobAlreadyExists, "blob already exists")
|
||||
ErrShardNodeUnsupport = newError(CodeUnsupport, "unsupport shard node")
|
||||
ErrShardConflicts = newError(CodeShardConflicts, "shard conflicts")
|
||||
ErrShardNodeNotLeader = Error(CodeShardNodeNotLeader)
|
||||
ErrShardRangeMismatch = Error(CodeShardRangeMismatch)
|
||||
ErrShardDoesNotExist = Error(CodeShardDoesNotExist)
|
||||
ErrShardNodeDiskNotFound = Error(CodeShardNodeDiskNotFound)
|
||||
ErrUnknownField = Error(CodeUnknownField)
|
||||
ErrShardRouteVersionNeedUpdate = Error(CodeShardRouteVersionNeedUpdate)
|
||||
ErrShardNoLeader = Error(CodeShardNoLeader)
|
||||
ErrIllegalSlices = Error(CodeIllegalSlices)
|
||||
ErrBlobAlreadyExists = Error(CodeBlobAlreadyExists)
|
||||
ErrShardNodeUnsupport = Error(CodeUnsupport)
|
||||
ErrShardConflicts = Error(CodeShardConflicts)
|
||||
ErrKeySizeTooLarge = Error(CodeKeySizeTooLarge)
|
||||
ErrValueSizeTooLarge = Error(CodeValueSizeTooLarge)
|
||||
)
|
||||
|
||||
@ -19,9 +19,15 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/cubefs/cubefs/blobstore/api/shardnode"
|
||||
apierr "github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
"github.com/cubefs/cubefs/blobstore/shardnode/storage"
|
||||
)
|
||||
|
||||
func (s *service) createBlob(ctx context.Context, req *shardnode.CreateBlobArgs) (resp shardnode.CreateBlobRet, err error) {
|
||||
if len(req.Name) > storage.MaxKeySize {
|
||||
err = apierr.ErrKeySizeTooLarge
|
||||
return
|
||||
}
|
||||
sid := req.Header.SpaceID
|
||||
space, err := s.catalog.GetSpace(ctx, sid)
|
||||
if err != nil {
|
||||
|
||||
@ -19,9 +19,14 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/cubefs/cubefs/blobstore/api/shardnode"
|
||||
apierr "github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
"github.com/cubefs/cubefs/blobstore/shardnode/storage"
|
||||
)
|
||||
|
||||
func (s *service) insertItem(ctx context.Context, req *shardnode.InsertItemArgs) error {
|
||||
if len(req.Item.ID) > storage.MaxKeySize {
|
||||
return apierr.ErrKeySizeTooLarge
|
||||
}
|
||||
sid := req.Header.SpaceID
|
||||
space, err := s.catalog.GetSpace(ctx, sid)
|
||||
if err != nil {
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
apierr "github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
"github.com/cubefs/cubefs/blobstore/util/bytespool"
|
||||
)
|
||||
|
||||
@ -38,6 +39,9 @@ func NewKV(buff []byte) *KV {
|
||||
}
|
||||
|
||||
func InitKV(key []byte, value *io.LimitedReader) (*KV, error) {
|
||||
if value.N > MaxValueSize {
|
||||
return nil, apierr.ErrValueSizeTooLarge
|
||||
}
|
||||
buf := bytespool.Alloc(keyFieldSize + valueFieldSize + int(len(key)) + int(value.N))
|
||||
n := 0
|
||||
// key
|
||||
|
||||
@ -19,6 +19,8 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
"github.com/cubefs/cubefs/blobstore/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -33,4 +35,10 @@ func TestKV(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, key, kv.Key())
|
||||
require.Equal(t, value, kv.Value())
|
||||
|
||||
_, err = InitKV(key, &io.LimitedReader{
|
||||
R: util.DiscardReader(MaxValueSize + 1),
|
||||
N: int64(MaxValueSize + 1),
|
||||
})
|
||||
require.Equal(t, err, errors.ErrValueSizeTooLarge)
|
||||
}
|
||||
|
||||
@ -23,6 +23,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxKeySize = 1 << 15
|
||||
MaxValueSize = 1 << 24
|
||||
|
||||
dataCF = "data"
|
||||
lockCF = "lock"
|
||||
writeCF = "write"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user