blynn / nex

Lexer for Go
http://cs.stanford.edu/~blynn/nex/
GNU General Public License v3.0
416 stars 47 forks source link

May hang into inf-loop in multi-level klein-closure #40

Closed wolfkdy closed 6 years ago

wolfkdy commented 7 years ago

I wrote a complex regex and run nex but found an 'out-of-memory' error. My vps has 4G memory so I doubt somewhere may went wrong. I tried to find a simpler regex which can cause the same problem, finally, I found one like below:

/(([ \t]*)*)*/ { / eat up whitespace / }

It is sensed that nex may hang into inf-loop in cases which has nested klein-closures. the crash is sth like below:

fatal error: runtime: out of memory

runtime stack: runtime.throw(0x546c99, 0x16) /usr/local/go/src/runtime/panic.go:566 +0x95 runtime.sysMap(0xc440200000, 0x20000000, 0xc4401a3e00, 0x5ff718) /usr/local/go/src/runtime/mem_linux.go:219 +0x1d0 runtime.(mheap).sysAlloc(0x5e6ec0, 0x20000000, 0x0) /usr/local/go/src/runtime/malloc.go:407 +0x37a runtime.(mheap).grow(0x5e6ec0, 0x10000, 0x0) /usr/local/go/src/runtime/mheap.go:726 +0x62 runtime.(mheap).allocSpanLocked(0x5e6ec0, 0x10000, 0x0) /usr/local/go/src/runtime/mheap.go:630 +0x4f2 runtime.(mheap).allocStack(0x5e6ec0, 0x10000, 0x0) /usr/local/go/src/runtime/mheap.go:597 +0x62 runtime.stackalloc(0xc420000000, 0xc4301a3ee0, 0x8000000, 0xc4200001a0, 0x0, 0x0) /usr/local/go/src/runtime/stack.go:395 +0x2ed runtime.copystack(0xc4200001a0, 0x20000000, 0x5e3d01) /usr/local/go/src/runtime/stack.go:839 +0x83 runtime.newstack() /usr/local/go/src/runtime/stack.go:1070 +0x370 runtime.morestack() /usr/local/go/src/runtime/asm_amd64.s:366 +0x7f

goroutine 1 [copystack]: main.gen.func17.1(0x2) /home/kongdeyu/goprojs/src/github.com/blynn/nex.go:522 fp=0xc4301a42b8 sp=0xc4301a42b0 main.gen.func17.1(0x1) /home/kongdeyu/goprojs/src/github.com/blynn/nex.go:527 +0xf8 fp=0xc4301a4308 sp=0xc4301a42b8 main.gen.func17.1(0x2) /home/kongdeyu/goprojs/src/github.com/blynn/nex.go:527 +0xf8 fp=0xc4301a4358 sp=0xc4301a4308 main.gen.func17.1(0x1) /home/kongdeyu/goprojs/src/github.com/blynn/nex.go:527 +0xf8 fp=0xc4301a43a8 sp=0xc4301a4358 main.gen.func17.1(0x2) /home/kongdeyu/goprojs/src/github.com/blynn/nex.go:527 +0xf8 fp=0xc4301a43f8 sp=0xc4301a43a8 main.gen.func17.1(0x1)

blynn commented 6 years ago

Thanks for the bug report. Fixed.