spakin/awk

SIGSEGV: segmentation violation

suntong opened this issue · 3 comments

awk is giving me SIGSEGV: segmentation violation when the input is huge.

I use it in https://github.com/suntong/fss. It's OK when the output is small, when running

ls -ld `ls -1d /etc/* | fss dirs`

However, when I try to feed it with huge input, it errors out:

$ mlocate /mnt/huge_volumn | fss dirs
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x66c52f]

goroutine 1 [running]:
github.com/spakin/awk.(*Script).Run.func1(0xc420305cc0)
	/path/to/go/src/github.com/spakin/awk/script.go:860 +0xc3
panic(0x6b23c0, 0x8601a0)
	/usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
github.com/spakin/awk.(*Script).Run.func2.1()
	/path/to/go/src/github.com/spakin/awk/script.go:911 +0x5e
panic(0x6b23c0, 0x8601a0)
	/usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
main.cmdDirs.func1(0xc4201f6000)
	/home/tong/l/gg/suntong/fss/cmdDirs.go:76 +0xbf
github.com/spakin/awk.(*Script).Run.func2(0xc4201f6000)
	/path/to/go/src/github.com/spakin/awk/script.go:920 +0xda
github.com/spakin/awk.(*Script).Run(0xc4201f6000, 0x83a380, 0xc42000e010, 0x0, 0x0)
	/path/to/go/src/github.com/spakin/awk/script.go:926 +0x29c
main.cmdDirs(0xc420096370, 0x6acce0)
	/home/tong/l/gg/suntong/fss/cmdDirs.go:83 +0x3ad
main.dirsCLI(0xc420096370, 0x0, 0x0)
	/home/tong/l/gg/suntong/fss/cmdDirs.go:59 +0x5b
github.com/mkideal/cli.(*Command).RunWith(0x865e60, 0xc42000c510, 0x1, 0x1, 0x83a3c0, 0xc42000e018, 0x0, 0x0, 0x0, 0x0, ...)
	/path/to/go/src/github.com/mkideal/cli/command.go:205 +0x2ec
github.com/mkideal/cli.(*Command).Run(0x865e60, 0xc42000c510, 0x1, 0x1, 0x865e60, 0x6bff20)
	/path/to/go/src/github.com/mkideal/cli/command.go:162 +0x95
main.main()
	/path/to/git/suntong/fss/fssMain.go:38 +0x13e

Please double-check.
Thanks

You can just try out the awk script part and skip all the dependencies of "github.com/mkideal/cli" "github.com/suntong/set", and file extension checking if you want. The result would be the same.

Observation:

panic(0x6b23c0, 0x8601a0)
	/usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
main.cmdDirs.func1(0xc4201f6000)
	/home/tong/l/gg/suntong/fss/cmdDirs.go:76 +0xbf

Hypothesis:

  • stt is nil.

Conclusion:

  • os.Stat is failing, but the error value is being ignored.

Solution:

// or not a dir
stt, err := os.Stat(fn)
if err != nil {
	s.Next()
}
if !stt.IsDir() {
	s.Next()
}

Bang on! My bad. Sorry to bothering you with such low level mistakes. I should have gone to sleep instead of burning my midnight oils. Thanks for helping!