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

[bug] slice bounds out of range [-1:] #95

Closed
emaborsa opened this issue May 18, 2022 · 1 comment · Fixed by #103
Closed

[bug] slice bounds out of range [-1:] #95

emaborsa opened this issue May 18, 2022 · 1 comment · Fixed by #103
Labels

Comments

@emaborsa
Copy link

emaborsa commented May 18, 2022

I started with a simple example:

ttt := make([]*feeds.Item, 0, len(items))
for _, r := range items {
    tt := feeds.Item{
	Id: fmt.Sprintf("%d", r.RequestID),
    }
    ttt = append(ttt, &tt)
}       
now := time.Now()
feed := &feeds.Feed{
    Title:       "sfdsdfd.net blog",
    Link:        &feeds.Link{Href: "http://sdfsdfd.net/blog"},
    Description: "discussion about tech, footie, photos",
    Author:      &feeds.Author{Name: "Jassdfdsdfdon sdfsdf", Email: "fdhsfjgz@ertete.net"},
    Created:     now,
    Items:       ttt,
}

atom, err := feed.ToAtom()
if err != nil {
    render.Render(w, r, httperr.ErrInternalServer(err.Error()))
}
render.PlainText(w, r, atom)

At the command atom, err := feed.ToAtom() I get the following error:

http: panic serving [::1]:39096: runtime error: slice bounds out of range [-1:]
goroutine 50 [running]:
net/http.(*conn).serve.func1()
	/usr/lib/go-1.18/src/net/http/server.go:1825 +0x148
panic({0xb99300, 0xc0002928b8})
	/usr/lib/go-1.18/src/runtime/panic.go:844 +0x25a
github.com/go-chi/chi/middleware.prettyStack.decorateFuncCallLine({}, {0xc0002c7a69, 0x1b}, 0x1, 0x8)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:130 +0x737
github.com/go-chi/chi/middleware.prettyStack.decorateLine({}, {0xc0002c7a69, 0x1b}, 0x1, 0x8)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:106 +0x21c
github.com/go-chi/chi/middleware.prettyStack.parse({}, {0xc00049c000, 0x168e, 0x2000}, {0xb54440, 0xeb2380})
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:89 +0x8fa
github.com/go-chi/chi/middleware.PrintPrettyStack({0xb54440, 0xeb2380})
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:46 +0x89
github.com/go-chi/chi/middleware.(*defaultLogEntry).Panic(0xc000290900, {0xb54440, 0xeb2380}, {0xc000498000, 0x1518, 0x2000})
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/logger.go:165 +0x45
github.com/go-chi/chi/middleware.Recoverer.func1.1()
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:28 +0x15f
panic({0xb54440, 0xeb2380})
	/usr/lib/go-1.18/src/runtime/panic.go:844 +0x25a
github.com/gorilla/feeds.newAtomEntry(0xc000494000)
	/home/emaborsa/go/pkg/mod/github.com/gorilla/feeds@v1.1.1/atom.go:113 +0x657
github.com/gorilla/feeds.(*Atom).AtomFeed(0xc000286018)
	/home/emaborsa/go/pkg/mod/github.com/gorilla/feeds@v1.1.1/atom.go:156 +0x5f1
github.com/gorilla/feeds.(*Atom).FeedXml(0xc000286018)
	/home/emaborsa/go/pkg/mod/github.com/gorilla/feeds@v1.1.1/atom.go:163 +0x29
github.com/gorilla/feeds.ToXML({0xc2f1e0, 0xc000286018})
	/home/emaborsa/go/pkg/mod/github.com/gorilla/feeds@v1.1.1/feed.go:78 +0x5d
github.com/gorilla/feeds.(*Feed).ToAtom(0xc0002b00b0)
	/home/emaborsa/go/pkg/mod/github.com/gorilla/feeds@v1.1.1/feed.go:104 +0x99
github.com/HGV/guest-requests-api/app.Application.GetHGVRequests({{{0xc0001bc3f0}, {0xc0001bc3f0}}}, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/code/guest-requests-api/app/hgv_requests.go:120 +0xb65
net/http.HandlerFunc.ServeHTTP(0xc00000eca8, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc000092de0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 +0x27e
net/http.HandlerFunc.ServeHTTP(0xc000021bb0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc000092de0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 +0xfa
github.com/go-chi/chi/v5.(*Mux).Mount.func1({0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 +0x204
net/http.HandlerFunc.ServeHTTP(0xc00007ffc0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc000092d80, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 +0x27e
net/http.HandlerFunc.ServeHTTP(0xc000021bd0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc000092d80, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 +0xfa
github.com/go-chi/chi/v5.(*Mux).Mount.func1({0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 +0x204
net/http.HandlerFunc.ServeHTTP(0xc00007ffe0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc000092c00, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 +0x27e
net/http.HandlerFunc.ServeHTTP(0xc000021b10, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/middleware.Timeout.func1.1({0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2500)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/timeout.go:45 +0x1fe
net/http.HandlerFunc.ServeHTTP(0xc00007ff40, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2400)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/middleware.Recoverer.func1({0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2400)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/recoverer.go:37 +0xf8
net/http.HandlerFunc.ServeHTTP(0xc00000eab0, {0x7f8c1d8b8c78, 0xc0002b2200}, 0xc0002d2400)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/middleware.RequestLogger.func1.1({0xc33370, 0xc0002b40e0}, 0xc0002d2300)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/logger.go:57 +0x266
net/http.HandlerFunc.ServeHTTP(0xc0001fa750, {0xc33370, 0xc0002b40e0}, 0xc0002d2300)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/middleware.RealIP.func1({0xc33370, 0xc0002b40e0}, 0xc0002d2300)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/realip.go:34 +0xac
net/http.HandlerFunc.ServeHTTP(0xc00000eac8, {0xc33370, 0xc0002b40e0}, 0xc0002d2300)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/middleware.RequestID.func1({0xc33370, 0xc0002b40e0}, 0xc0002d2200)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi@v1.5.4/middleware/request_id.go:76 +0x25f
net/http.HandlerFunc.ServeHTTP(0xc00000eae0, {0xc33370, 0xc0002b40e0}, 0xc0002d2200)
	/usr/lib/go-1.18/src/net/http/server.go:2084 +0x43
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc000092c00, {0xc33370, 0xc0002b40e0}, 0xc0002d2200)
	/home/emaborsa/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88 +0x288
net/http.serverHandler.ServeHTTP({0xc0001dc1c0}, {0xc33370, 0xc0002b40e0}, 0xc0002d2100)
	/usr/lib/go-1.18/src/net/http/server.go:2916 +0x474
net/http.(*conn).serve(0xc0002f6000, {0xc33860, 0xc0002b20c0})
	/usr/lib/go-1.18/src/net/http/server.go:1966 +0x193c
created by net/http.(*Server).Serve
	/usr/lib/go-1.18/src/net/http/server.go:3071 +0x9cf
@emaborsa emaborsa added the bug label May 18, 2022
@emaborsa
Copy link
Author

Debugging it i noticed there is a NullPointerException at line 113 of atom.go. There should be a check or the property sould not be nullable.

@coreydaley coreydaley moved this to 📋 Backlog in Gorilla Web Toolkit Aug 17, 2023
AlexVulaj pushed a commit that referenced this issue Sep 22, 2023
## What type of PR is this? (check all applicable)
- [x] Bug Fix

## Description
Check for nil link in feed to avoid runtime panic

## Related Issue
- Closes #95

## Added/updated tests?
- [x] Yes
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Gorilla Web Toolkit Sep 22, 2023
Bios-Marcel pushed a commit to Bios-Marcel/feeds that referenced this issue Apr 27, 2024
## What type of PR is this? (check all applicable)
- [x] Bug Fix

## Description
Check for nil link in feed to avoid runtime panic

## Related Issue
- Closes gorilla#95

## Added/updated tests?
- [x] Yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant