swarm/storage: add chunk size validation to localstore

This commit is contained in:
Anton Evangelatov 2018-08-14 11:31:24 +02:00
parent c56a21b67b
commit 92ef6db7b7
3 changed files with 3 additions and 12 deletions

View file

@ -24,6 +24,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/metrics"
cp "github.com/ethereum/go-ethereum/swarm/chunk"
"github.com/ethereum/go-ethereum/swarm/log"
"github.com/ethereum/go-ethereum/swarm/storage/mock"
)
@ -98,8 +99,8 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
// After the LDBStore.Put, it is ensured that the MemStore
// contains the chunk with the same data, but nil ReqC channel.
func (ls *LocalStore) Put(ctx context.Context, chunk *Chunk) {
if l := len(chunk.SData); l < 9 {
log.Debug("incomplete chunk data", "addr", chunk.Addr, "length", l)
if l := len(chunk.SData); l < 9 || l > cp.DefaultSize+8 {
log.Debug("invalid chunk data", "addr", chunk.Addr, "len", l)
chunk.SetErrored(ErrChunkInvalid)
chunk.markAsStored()
return

View file

@ -355,12 +355,3 @@ func (v *ContentAddressValidator) Validate(addr Address, data []byte) bool {
return bytes.Equal(hash, addr[:])
}
// SizeValidator provides method for validation of max chunk data size
type SizeValidator struct {
}
// Validate that the chunk has valid size
func (v *SizeValidator) Validate(_ Address, data []byte) bool {
return len(data) <= 8+chunk.DefaultSize
}

View file

@ -203,7 +203,6 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
validators := []storage.ChunkValidator{
storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)),
&storage.SizeValidator{},
}
if resourceHandler != nil {
validators = append(validators, resourceHandler)