Skip to content

Commit

Permalink
sia: catch invalid v1 conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Nov 21, 2023
1 parent 4b488e1 commit 5b8de20
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sia/sia.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ipfs/boxo/ipld/unixfs/importer/balanced"
ihelpers "github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
"go.sia.tech/fsd/config"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/worker"
Expand Down Expand Up @@ -137,6 +138,10 @@ func (n *Node) getBlock(ctx context.Context, c cid.Cid) (Block, error) {
v1Cid := cid.NewCidV1(c.Type(), c.Hash())
return n.store.GetBlock(ctx, v1Cid)
case 1:
h := c.Hash()
if c.Prefix().Codec != multihash.SHA2_256 || len(h) != 32 {
return Block{}, ErrNotFound // CID is not convertible to v0
}
v0Cid := cid.NewCidV0(c.Hash())
return n.store.GetBlock(ctx, v0Cid)
}
Expand Down

0 comments on commit 5b8de20

Please sign in to comment.