Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unixfs): check for errors before dereferencing the link #8508

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
20 changes: 20 additions & 0 deletions test/sharness/t0260-sharding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's a less fragile way to detect this error at the moment

cat ls_err_out &&
test_cmp exp_err_out ls_err_out
'
}

test_list_incomplete_dir

test_done