Skip to content

Commit

Permalink
Merge pull request ipfs/go-blockservice#65 from ipfs/fix/race-valid-cid
Browse files Browse the repository at this point in the history
Avoid modifying passed in slice of cids

This commit was moved from ipfs/go-blockservice@622c072
  • Loading branch information
Kubuxu authored Jun 24, 2020
2 parents bfe5fc1 + ed1f46e commit b261c29
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// 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, 0, len(ks))
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err == nil {
ks2 = append(ks2, c)
} else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
}
}
ks = ks2
}

var misses []cid.Cid
for _, c := range ks {
Expand Down

0 comments on commit b261c29

Please sign in to comment.