Skip to content

Commit

Permalink
ipld/unixfs/hamt: catch panic in walkChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Jun 26, 2023
1 parent 290613a commit 2e58e9d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ipld/unixfs/hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ import (
"os"
"sync"

"golang.org/x/sync/errgroup"

format "github.com/ipfs/boxo/ipld/unixfs"
"github.com/ipfs/boxo/ipld/unixfs/internal"

dag "github.com/ipfs/boxo/ipld/merkledag"
bitfield "github.com/ipfs/go-bitfield"
cid "github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
"golang.org/x/sync/errgroup"
)

var log = logging.Logger("unixfs-hamt")

const (
// HashMurmur3 is the multiformats identifier for Murmur3
HashMurmur3 uint64 = 0x22
Expand Down Expand Up @@ -429,8 +431,13 @@ type listCidsAndShards struct {
func (ds *Shard) walkChildren(processLinkValues func(formattedLink *ipld.Link) error) (*listCidsAndShards, error) {
res := &listCidsAndShards{}

for idx, lnk := range ds.childer.links {
if nextShard := ds.childer.children[idx]; nextShard == nil {
for i := range ds.childer.children {
if nextShard := ds.childer.child(i); nextShard == nil {
lnk := ds.childer.link(i)
if lnk == nil {
log.Warnf("internal HAMT error: both link and shard nil at pos %d, dumping shard: %+v", i, *ds)
return nil, fmt.Errorf("internal HAMT error: both link and shard nil, check log")
}
lnkLinkType, err := ds.childLinkType(lnk)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2e58e9d

Please sign in to comment.