swarm/network, swarm/storage: validate chunk size (#17397)
* swarm/network, swarm/storage: validate default chunk size * swarm/bmt, swarm/network, swarm/storage: update BMT hash initialisation * swarm/bmt: move segmentCount to tests * swarm/chunk: change chunk.DefaultSize to be untyped const * swarm/storage: add size validator * swarm/storage: add chunk size validation to localstore * swarm/storage: move validation from localstore to validator * swarm/storage: global chunk rules in MRU
This commit is contained in:
committed by
Balint Gabor
parent
8a040de60b
commit
97887d98da
@@ -22,6 +22,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage/encryption"
|
||||
)
|
||||
|
||||
@@ -57,7 +58,7 @@ func NewHasherStore(chunkStore ChunkStore, hashFunc SwarmHasher, toEncrypt bool)
|
||||
refSize := int64(hashSize)
|
||||
if toEncrypt {
|
||||
refSize += encryption.KeyLength
|
||||
chunkEncryption = newChunkEncryption(DefaultChunkSize, refSize)
|
||||
chunkEncryption = newChunkEncryption(chunk.DefaultSize, refSize)
|
||||
}
|
||||
|
||||
return &hasherStore{
|
||||
@@ -190,9 +191,9 @@ func (h *hasherStore) decryptChunkData(chunkData ChunkData, encryptionKey encryp
|
||||
|
||||
// removing extra bytes which were just added for padding
|
||||
length := ChunkData(decryptedSpan).Size()
|
||||
for length > DefaultChunkSize {
|
||||
length = length + (DefaultChunkSize - 1)
|
||||
length = length / DefaultChunkSize
|
||||
for length > chunk.DefaultSize {
|
||||
length = length + (chunk.DefaultSize - 1)
|
||||
length = length / chunk.DefaultSize
|
||||
length *= h.refSize
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user