From 5b8de2074b7518a4638f8ae0384966c1a7d0068e Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Mon, 20 Nov 2023 23:38:13 -0800 Subject: [PATCH] sia: catch invalid v1 conversions --- sia/sia.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sia/sia.go b/sia/sia.go index 350d6a9..74641e5 100644 --- a/sia/sia.go +++ b/sia/sia.go @@ -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" @@ -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) }