Unverified Commit 622c072d authored by Jakub Sztandera's avatar Jakub Sztandera Committed by GitHub

Merge pull request #65 from ipfs/fix/race-valid-cid

Avoid modifying passed in slice of cids
parents f12f8ae1 5ca73b91
......@@ -273,17 +273,26 @@ 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 {
if err := verifcid.ValidateCid(c); err != nil {
allValid = false
break
}
}
if !allValid {
ks2 := make([]cid.Cid, 0, len(ks))
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err == nil {
ks[k] = c
k++
ks2 = append(ks2, c)
} else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
}
}
ks = ks[:k]
ks = ks2
}
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