@cryptotaxi247 / kubo / commits / b5a45a1d9

cid-sec: fix bitswap strom caused by insecure CIDs

When we introduced CID security we didn't take into account that bitswap might repeatly try getting the objects from the network if it fails putting them into the blockstore. Solution from this is not requesting those objects from bitswap. The proper solution of failing at CID creation will make in much more cleaner in future. License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Apr 18, 2018 at 16:43 UTC b5a45a1d9052567b0de315ada4d108b1c2ccd9dd
1 file changed +13 -6
blockservice/blockservice.go
+13 -6
@@ -251,15 +251,22 @@ func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan bloc
251
252 func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block {
253 out := make(chan blocks.Block)
254 - for _, c := range ks {
255 - // hash security
256 - if err := verifcid.ValidateCid(c); err != nil {
257 - log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
258 - }
259 - }
254
255 go func() {
256 defer close(out)
257 +
258 + k := 0
259 + for _, c := range ks {
260 + // hash security
261 + if err := verifcid.ValidateCid(c); err == nil {
262 + ks[k] = c
263 + k++
264 + } else {
265 + log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
266 + }
267 + }
268 + ks = ks[:k]
269 +
270 var misses []*cid.Cid
271 for _, c := range ks {
272 hit, err := bs.Get(c)