k0kubun/pp

Unable to print invalid address

k0kubun opened this issue · 2 comments

original: x-motemen/gore#51

If data structure has invalid pointer which is introduced by unsafe package's API or unsafe-related packages, pp crashes by referring the address.

Note that go-spew has the exact same crash bug. I'm not sure this issue is worth fixing...

Stacktraces

k0kubun/pp
unexpected fault address 0xffffffffffffffff
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xffffffffffffffff pc=0x40be94a]

goroutine 1 [running]:
runtime.throw(0x40fa974, 0x5)
	/usr/local/Cellar/go/1.12/libexec/src/runtime/panic.go:617 +0x72 fp=0xc0000b15a8 sp=0xc0000b1578 pc=0x402aea2
runtime.sigpanic()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/signal_unix.go:397 +0x401 fp=0xc0000b15d8 sp=0xc0000b15a8 pc=0x403d771
reflect.Value.Int(...)
	/usr/local/Cellar/go/1.12/libexec/src/reflect/value.go:958
github.com/k0kubun/pp.(*printer).raw(0xc0000a8300, 0x0, 0x0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:358 +0x1aa fp=0xc0000b1650 sp=0xc0000b15d8 pc=0x40be94a
github.com/k0kubun/pp.(*printer).String(0xc0000a8300, 0xc0000a6260, 0xc0000a8300)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:59 +0x86 fp=0xc0000b16f8 sp=0xc0000b1650 pc=0x40bb736
github.com/k0kubun/pp.(*printer).format(0xc0000a81c0, 0x40f9ae0, 0xc0000a6260, 0xc0000a6260, 0x40d3440)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:389 +0xa1 fp=0xc0000b1720 sp=0xc0000b16f8 pc=0x40bf1a1
github.com/k0kubun/pp.(*printer).printStruct.func1()
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:191 +0x195 fp=0xc0000b1888 sp=0xc0000b1720 pc=0x40bf6b5
github.com/k0kubun/pp.(*printer).indented(...)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:343
github.com/k0kubun/pp.(*printer).printStruct(0xc0000a81c0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:187 +0x299 fp=0xc0000b1920 sp=0xc0000b1888 pc=0x40bca49
github.com/k0kubun/pp.(*printer).String(0xc0000a81c0, 0xc0000a6140, 0xc0000a81c0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:67 +0x60b fp=0xc0000b19c8 sp=0xc0000b1920 pc=0x40bbcbb
github.com/k0kubun/pp.(*printer).format(0xc0000a8180, 0x40f9ae0, 0xc0000a6140, 0xc0000a6140, 0xffffffffffffffff)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:389 +0xa1 fp=0xc0000b19f0 sp=0xc0000b19c8 pc=0x40bf1a1
github.com/k0kubun/pp.(*printer).printPtr(0xc0000a8180)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:296 +0x17a fp=0xc0000b1aa0 sp=0xc0000b19f0 pc=0x40bdd0a
github.com/k0kubun/pp.(*printer).String(0xc0000a8180, 0xc0000a6100, 0xc0000a8180)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:75 +0x4ca fp=0xc0000b1b48 sp=0xc0000b1aa0 pc=0x40bbb7a
github.com/k0kubun/pp.(*printer).format(0xc0000a8000, 0x40f9ae0, 0xc0000a6100, 0xc0000a6100, 0x40cdfc0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:389 +0xa1 fp=0xc0000b1b70 sp=0xc0000b1b48 pc=0x40bf1a1
github.com/k0kubun/pp.(*printer).printStruct.func1()
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:191 +0x195 fp=0xc0000b1cd8 sp=0xc0000b1b70 pc=0x40bf6b5
github.com/k0kubun/pp.(*printer).indented(...)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:343
github.com/k0kubun/pp.(*printer).printStruct(0xc0000a8000)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:187 +0x299 fp=0xc0000b1d70 sp=0xc0000b1cd8 pc=0x40bca49
github.com/k0kubun/pp.(*printer).String(0xc0000a8000, 0xffffffffffffffff, 0xc0000a8000)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:67 +0x60b fp=0xc0000b1e18 sp=0xc0000b1d70 pc=0x40bbcbb
github.com/k0kubun/pp.format(0x40df4e0, 0xffffffffffffffff, 0x300000002, 0xc000000180)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/printer.go:27 +0x43 fp=0xc0000b1e40 sp=0xc0000b1e18 pc=0x40bb383
github.com/k0kubun/pp.formatAll(0xc0000b1f78, 0x1, 0x1, 0xc000096008, 0xc000096008, 0x0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/pp.go:145 +0xb5 fp=0xc0000b1ef0 sp=0xc0000b1e40 pc=0x40bb0c5
github.com/k0kubun/pp.Print(0xc00004bf78, 0x1, 0x1, 0xc000020118, 0x0, 0x0)
	/Users/itchyny/.go/src/github.com/k0kubun/pp/pp.go:33 +0x43 fp=0xc0000b1f40 sp=0xc0000b1ef0 pc=0x40bafa3
main.main()
	/private/tmp/main.go:28 +0x81 fp=0xc0000b1f98 sp=0xc0000b1f40 pc=0x40c0641
runtime.main()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/proc.go:200 +0x20c fp=0xc0000b1fe0 sp=0xc0000b1f98 pc=0x402c7dc
runtime.goexit()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000b1fe8 sp=0xc0000b1fe0 pc=0x4053f01
exit status 2
davecgh/go-spew
unexpected fault address 0xffffffffffffffff
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xffffffffffffffff pc=0x40b782f]

goroutine 1 [running]:
runtime.throw(0x40f11e2, 0x5)
	/usr/local/Cellar/go/1.12/libexec/src/runtime/panic.go:617 +0x72 fp=0xc0000cb3c8 sp=0xc0000cb398 pc=0x402a972
runtime.sigpanic()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/signal_unix.go:397 +0x401 fp=0xc0000cb3f8 sp=0xc0000cb3c8 pc=0x403d241
reflect.Value.Int(...)
	/usr/local/Cellar/go/1.12/libexec/src/reflect/value.go:958
github.com/davecgh/go-spew/spew.(*formatState).format(0xc0000ec000, 0x40cb120, 0xffffffffffffffff, 0x1a5)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:242 +0x106f fp=0xc0000cb5b8 sp=0xc0000cb3f8 pc=0x40b782f
github.com/davecgh/go-spew/spew.(*formatState).format(0xc0000ec000, 0x40d6b80, 0xffffffffffffffff, 0x1b9)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:345 +0xcc0 fp=0xc0000cb778 sp=0xc0000cb5b8 pc=0x40b7480
github.com/davecgh/go-spew/spew.(*formatState).formatPtr(0xc0000ec000, 0x40c5ea0, 0xffffffffffffffff, 0x36)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:193 +0x777 fp=0xc0000cb8b8 sp=0xc0000cb778 pc=0x40b6337
github.com/davecgh/go-spew/spew.(*formatState).format(0xc0000ec000, 0x40c5ea0, 0xffffffffffffffff, 0x36)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:211 +0x1729 fp=0xc0000cba78 sp=0xc0000cb8b8 pc=0x40b7ee9
github.com/davecgh/go-spew/spew.(*formatState).format(0xc0000ec000, 0x40d6c00, 0xffffffffffffffff, 0x19)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:345 +0xcc0 fp=0xc0000cbc38 sp=0xc0000cba78 pc=0x40b7480
github.com/davecgh/go-spew/spew.(*formatState).Format(0xc0000ec000, 0x4110380, 0xc0000ee000, 0x76)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/format.go:389 +0xe6 fp=0xc0000cbcc8 sp=0xc0000cbc38 pc=0x40b80c6
fmt.(*pp).handleMethods(0xc0000ee000, 0xc000000076, 0xc0000cbd01)
	/usr/local/Cellar/go/1.12/libexec/src/fmt/print.go:583 +0x4b5 fp=0xc0000cbd68 sp=0xc0000cbcc8 pc=0x4095105
fmt.(*pp).printArg(0xc0000ee000, 0x40dd4c0, 0xc0000ec000, 0x76)
	/usr/local/Cellar/go/1.12/libexec/src/fmt/print.go:699 +0x20a fp=0xc0000cbe00 sp=0xc0000cbd68 pc=0x409536a
fmt.(*pp).doPrint(0xc0000ee000, 0xc0000ae0d0, 0x1, 0x1)
	/usr/local/Cellar/go/1.12/libexec/src/fmt/print.go:1147 +0xfd fp=0xc0000cbe88 sp=0xc0000cbe00 pc=0x4099e4d
fmt.Fprint(0x410f840, 0xc0000a6000, 0xc0000ae0d0, 0x1, 0x1, 0x1, 0x0, 0x0)
	/usr/local/Cellar/go/1.12/libexec/src/fmt/print.go:233 +0x58 fp=0xc0000cbef0 sp=0xc0000cbe88 pc=0x40921a8
fmt.Print(...)
	/usr/local/Cellar/go/1.12/libexec/src/fmt/print.go:243
github.com/davecgh/go-spew/spew.Print(0xc0000cbf78, 0x1, 0x1, 0xc00007a058, 0x0, 0x0)
	/Users/itchyny/.go/src/github.com/davecgh/go-spew/spew/spew.go:80 +0x7e fp=0xc0000cbf40 sp=0xc0000cbef0 pc=0x40b82fe
main.main()
	/private/tmp/main.go:28 +0x81 fp=0xc0000cbf98 sp=0xc0000cbf40 pc=0x40b8b21
runtime.main()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/proc.go:200 +0x20c fp=0xc0000cbfe0 sp=0xc0000cbf98 pc=0x402c2ac
runtime.goexit()
	/usr/local/Cellar/go/1.12/libexec/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000cbfe8 sp=0xc0000cbfe0 pc=0x40539d1
exit status 2

While it'd be useful if we could avoid a crash for sure, I'd like to mark this as wont-fix until somebody figures out how to reasonably do so. Ultimately, we could also consider that as a problem of the cgo library used by the caller of pp.