mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
swarm/storage: add chunk size validation to localstore
This commit is contained in:
parent
c56a21b67b
commit
92ef6db7b7
3 changed files with 3 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue