tigrawap / slit

slit - a modern PAGER for viewing logs, get more than most in less time
Other
469 stars 19 forks source link

Avoid 'index out of range' panic #75

Closed oswcab closed 5 years ago

oswcab commented 5 years ago

When parsing some escape characters, slit was panicking with an 'index out of range' error:

goroutine 207 [running]: ff/slit/ansi.NewAstring(0xc0001881c8, 0x4, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) /opt/klm-go/src/ff/slit/ansi/arune.go:78 +0x36d ff/slit.(Fetcher).filteredLine(0xc000010180, 0xc0001881c8, 0x4, 0x5, 0x97, 0x1a6a, 0x0, 0x0, 0x0, 0x0, ...) /opt/klm-go/src/ff/slit/fetcher.go:72 +0x80 ff/slit.(Fetcher).lineBuilder.func1.2(0xc000010180, 0xc00022e000, 0x100, 0x100, 0xc000188110, 0x97, 0xc0001881c8, 0x4, 0x5, 0x97, ...) /opt/klm-go/src/ff/slit/fetcher.go:198 +0x67 created by ff/slit.(*Fetcher).lineBuilder.func1 /opt/klm-go/src/ff/slit/fetcher.go:197 +0x31e panic: runtime error: index out of range

Check boundary values when handling escape characters to avoid this issue.

oswcab commented 5 years ago

Minimal reproducer reproducer.txt

tigrawap commented 5 years ago

Hm, it does not reproduce the problem for me on latest master

Also, I don't understand how this commit solves the problem, since this part of code already under if r == 27 && i != max-1 { // [27 91] is control sequence And every change of i continues mainloop, so I don't see how it could reach changed line without i !=max-1 being true

oswcab commented 5 years ago

You're right, I'm not longer able to reproduce the issue with latest master. Closing this pull request.