shiena / ansicolor

Ansicolor library provides color console in Windows as ANSICON for Golang.

Home Page:https://pkg.go.dev/github.com/shiena/ansicolor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic: index out of range

maja42 opened this issue · comments

I got the following panic from within this library:

panic: runtime error: slice bounds out of range

goroutine 21983 [running]:
myApp/vendor/github.com/shiena/ansicolor.(*ansiColorWriter).Write(0xc0421c2000, 0xc04f2485b0, 0xc1, 0xd0, 0xd0, 0x0, 0x0)
        myApp/vendor/github.com/shiena/ansicolor/ansicolor_windows.go:384 +0x52b
myApp/vendor/github.com/sirupsen/logrus.(*Entry).write(0xc04277e060)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:247 +0x158
myApp/vendor/github.com/sirupsen/logrus.Entry.log(0xc0421cc6c0, 0xc0577a6900, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:219 +0x1c8
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Log(0xc0421b9e60, 0xc000000005, 0xc057793d70, 0x1, 0x1)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:256 +0xbe
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Logf(0xc0421b9e60, 0x5, 0xa889c1, 0x5f, 0xc042047440, 0x4, 0x4)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:301 +0xe6
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Debugf(0xc0421b9e60, 0xa889c1, 0x5f, 0xc042047440, 0x4, 0x4)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:309 +0x6c
...

The offending line is nw, err = cw.w.Write(p[first:last])

@maja42 Please tell me the steps to reproduce.

I'm not sure what caused this issue. It happened at random times during runtime, usually several minutes after the application started.

At first, I used the go-library https://github.com/mattn/go-colorable, but that library had the exact same issue: it paniced due to a string out-of-bounds-range.
Therefore, I switched to this library - but found out that it apparently has the same issue.
It might have something to do on how I create terminal windows on Windows - see my issue #12.

Since I only required ansicolor support for logrus outputs and since the logrus project already implemented that in their core library, I'm not using ansicolor anymore.

got same problem

solved it by comment log.setNoLock.