Avoid modifying passed in slice of cids

Signed-off-by: default avatarJakub Sztandera <kubuxu@protocol.ai>
parent f12f8ae1
......@@ -273,17 +273,28 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
go func() {
defer close(out)
k := 0
allValid := true
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err == nil {
ks[k] = c
k++
} else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
if err := verifcid.ValidateCid(c); err != nil {
allValid = false
break
}
}
ks = ks[:k]
if !allValid {
ks2 := make([]cid.Cid, len(ks))
k := 0
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err == nil {
ks2[k] = c
k++
} else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
}
}
ks = ks2[:k]
}
var misses []cid.Cid
for _, c := range ks {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment