From 9f03f1ff14c7f1b1d3461b2b4a6893f0c6ba992b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 12 Oct 2021 12:39:39 -0700 Subject: [PATCH 1/2] fix(unixfs): check for errors before dereferencing the link If there's an error, the link will be nil, and this will panic. --- core/coreapi/unixfs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index 53d13a3a497..6146f807a71 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -217,13 +217,13 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p path.Path, opts ...options.Unixf } func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, settings *options.UnixfsLsSettings) coreiface.DirEntry { + if linkres.Err != nil { + return coreiface.DirEntry{Err: linkres.Err} + } + lnk := coreiface.DirEntry{ Name: linkres.Link.Name, Cid: linkres.Link.Cid, - Err: linkres.Err, - } - if lnk.Err != nil { - return lnk } switch lnk.Cid.Type() { From a18b51b9eaca7d2ba2aefdfad482e8128a3c1bdf Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 25 Oct 2021 11:54:48 -0400 Subject: [PATCH 2/2] test: test ls incomplete sharded directory --- test/sharness/t0260-sharding.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/sharness/t0260-sharding.sh b/test/sharness/t0260-sharding.sh index 20be436c7a3..458eec133e9 100755 --- a/test/sharness/t0260-sharding.sh +++ b/test/sharness/t0260-sharding.sh @@ -117,4 +117,24 @@ test_add_large_dir_v1 "$SHARDEDV1" test_kill_ipfs_daemon +test_list_incomplete_dir() { + test_expect_success "ipfs add (CIDv1) on very large directory with sha3 succeeds" ' + ipfs add -r -q --cid-version=1 --hash=sha3-256 --pin=false testdata | tail -n1 > sharddir_out && + largeSHA3dir=$(cat sharddir_out) + ' + + test_expect_success "delete intermediate node from DAG" ' + ipfs block rm "/ipld/$largeSHA3dir/Links/0/Hash" + ' + + test_expect_success "can list part of the directory" ' + ipfs ls "$largeSHA3dir" 2> ls_err_out + echo "Error: merkledag: not found" > exp_err_out && + cat ls_err_out && + test_cmp exp_err_out ls_err_out + ' +} + +test_list_incomplete_dir + test_done