ansicolor icon indicating copy to clipboard operation
ansicolor copied to clipboard

panic: index out of range

Open maja42 opened this issue 6 years ago • 4 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 avatar Feb 22 '19 14:02 maja42

@maja42 Please tell me the steps to reproduce.

shiena avatar Mar 05 '19 16:03 shiena

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.

maja42 avatar Mar 11 '19 12:03 maja42

got same problem

leeefang avatar Jun 25 '19 07:06 leeefang

solved it by comment log.setNoLock.

leeefang avatar Jun 25 '19 07:06 leeefang