From 0858dc62aa7303c0da67289eee590013730c631b Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 30 Jul 2021 11:33:53 -0700 Subject: [PATCH 1/2] fix: avoid panic on short hash (caught higher up but should still be fixed) --- core/corehttp/gateway_indexPage.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/corehttp/gateway_indexPage.go b/core/corehttp/gateway_indexPage.go index 6e1722116..3bee4822b 100644 --- a/core/corehttp/gateway_indexPage.go +++ b/core/corehttp/gateway_indexPage.go @@ -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:]) } From 66a76d27f36f202f006a6fe04809df1a3529a3be Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 30 Jul 2021 11:34:15 -0700 Subject: [PATCH 2/2] fix: abort when we fail to resolve CIDs I believe we figured that these were for "informational purposes", but really, we _should_ always be able to resolve names to CIDs. If we can't, there's probably something wrong with the directory. --- core/corehttp/gateway_handler.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index ccec95b01..8e8300b65 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -391,11 +391,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request size = humanize.Bytes(uint64(s)) } - hash := "" - if r, err := i.api.ResolvePath(r.Context(), ipath.Join(resolvedPath, dirit.Name())); err == nil { - // Path may not be resolved. Continue anyways. - hash = r.Cid().String() + resolved, err := i.api.ResolvePath(r.Context(), ipath.Join(resolvedPath, dirit.Name())) + if err != nil { + internalWebError(w, err) + return } + hash := resolved.Cid().String() // See comment above where originalUrlPath is declared. di := directoryItem{