Skip to content

Commit

Permalink
fix: avoid out of bounds error when rendering short hashes
Browse files Browse the repository at this point in the history
The panic is caught higher up the stack so it can't crash the node, but
it's still "not good".
  • Loading branch information
Stebalien committed Jul 30, 2021
1 parent cab67f6 commit 39c76f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func breadcrumbs(urlPath string, dnslinkOrigin bool) []breadcrumb {
}

func shortHash(hash string) string {
if len(hash) <= 8 {
return hash
}
return (hash[0:4] + "\u2026" + hash[len(hash)-4:])
}

Expand Down
19 changes: 19 additions & 0 deletions test/sharness/t0046-id-hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,23 @@ test_expect_success "but can fetch it anyway (filestore enabled)" '
test_cmp junk.txt actual
'

test_launch_ipfs_daemon

test_expect_success "can add a directory with an inline file" '
echo "$ID_HASH0_CONTENTS" > file.txt &&
HASH="$(ipfs add -Q -w --raw-leaves --inline file.txt)"
'

test_expect_success "the hash matches" '
ipfs files stat --hash "/ipfs/$HASH/file.txt" &&
[[ "$(ipfs files stat --hash "/ipfs/$HASH/file.txt")" == "$ID_HASH0" ]]
'

test_expect_success "directory listing works" '
curl "$GWAY_ADDR/ipfs/$HASH" > list_response &&
test_should_contain "$ID_HASH0" list_response
'

test_kill_ipfs_daemon

test_done

0 comments on commit 39c76f8

Please sign in to comment.