Closed decke closed 3 years ago
It seems one of my feeds returns nothing and so triggers a panic because of a missing length check in src/parser/feed.go:21.
src/parser/feed.go:21
panic: runtime error: index out of range [0] with length 0 goroutine 343937 [running]: github.com/nkanaev/yarr/src/parser.sniff(0xc00016f7ba, 0x2, 0x2, 0xc00016f7ba, 0x2) github.com/nkanaev/yarr/src/parser/feed.go:21 +0x390 github.com/nkanaev/yarr/src/parser.Parse(0x3da0c0, 0xc00049ff80, 0xc000642d80, 0x18, 0x3da440) github.com/nkanaev/yarr/src/parser/feed.go:59 +0x245 github.com/nkanaev/yarr/src/worker.listItems(0x4c, 0xc0002f4318, 0xc000642030, 0x14, 0x0, 0x0, 0xc0003fc0a0, 0x1d, 0xc0000240f0, 0 x23, ...) github.com/nkanaev/yarr/src/worker/crawler.go:193 +0x385 github.com/nkanaev/yarr/src/worker.(*Worker).worker(0xc00007dd10, 0xc000361c80, 0xc00037a060) github.com/nkanaev/yarr/src/worker/worker.go:136 +0x145 created by github.com/nkanaev/yarr/src/worker.(*Worker).refresher github.com/nkanaev/yarr/src/worker/worker.go:117 +0xcf 2021/06/30 09:43:24 main.go:86: using db file /var/db/yarr/storage.db 2021/06/30 09:43:24 main.go:133: starting server at http://10.192.0.5:7070 2021/06/30 09:43:24 worker.go:105: Refreshing feeds 2021/06/30 09:43:24 worker.go:76: auto-refresh 30m: starting
I simply added a length check that fixes it for me.
--- src/parser/feed.go.orig 2021-06-07 09:07:20 UTC +++ src/parser/feed.go @@ -18,6 +18,11 @@ type processor func(r io.Reader) (*Feed, error) func sniff(lookup string) (string, processor) { lookup = strings.TrimSpace(lookup) lookup = strings.TrimLeft(lookup, "\x00\xEF\xBB\xBF\xFE\xFF") + + if len(lookup) < 1 { + return "", nil + } + switch lookup[0] { case '<': decoder := xmlDecoder(strings.NewReader(lookup))
thanks! patch added in https://github.com/nkanaev/yarr/commit/d203d38de68bf1c25439b70a3c7f64cb95c268db
It seems one of my feeds returns nothing and so triggers a panic because of a missing length check in
src/parser/feed.go:21
.I simply added a length check that fixes it for me.