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 ...@@ -273,17 +273,26 @@ func getBlocks(ctx context.Context, ks []cid.Cid, bs blockstore.Blockstore, fget
go func() { go func() {
defer close(out) 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 { for _, c := range ks {
// hash security // hash security
if err := verifcid.ValidateCid(c); err == nil { if err := verifcid.ValidateCid(c); err == nil {
ks[k] = c ks2 = append(ks2, c)
k++
} else { } else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err) log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
} }
} }
ks = ks[:k] ks = ks2
}
var misses []cid.Cid var misses []cid.Cid
for _, c := range ks { 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