Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

fix(hamt): catch panic in walkChildren #123

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ import (
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"
dag "github.com/ipfs/go-merkledag"
)

var log = logging.Logger("unixfs")

const (
// HashMurmur3 is the multiformats identifier for Murmur3
HashMurmur3 uint64 = 0x22
Expand Down Expand Up @@ -415,8 +418,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