davecgh / go-spew

Implements a deep pretty printer for Go data structures to aid in debugging
ISC License
6.1k stars 367 forks source link

Slice index out of range panic #134

Open lchanglyft opened 3 years ago

lchanglyft commented 3 years ago

I'm calling Sdump on a complex struct and it seems to go out of bounds on a slice:

runtime.gopanic
    /opt/go/src/runtime/panic.go:965
reflect.Value.Index
    /opt/go/src/reflect/value.go:962
github.com/davecgh/go-spew/spew.(*dumpState).dumpSlice
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:238
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:352
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:394
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:391
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dumpSlice
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:238
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:352
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dumpSlice
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:238
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:352
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:421
github.com/davecgh/go-spew/spew.(*dumpState).dumpPtr
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:154
github.com/davecgh/go-spew/spew.(*dumpState).dump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:262
github.com/davecgh/go-spew/spew.fdump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:465
github.com/davecgh/go-spew/spew.Sdump
    /code/.cache/gopath/pkg/mod/github.com/davecgh/go-spew@v1.1.2-0.20180830191138-d8f796af33cc/spew/dump.go:480

Here's the code block in value that it's hitting:

    case Slice:
        // Element flag same as Elem of Ptr.
        // Addressable, indirect, possibly read-only.
        s := (*unsafeheader.Slice)(v.ptr)
        if uint(i) >= uint(s.Len) {
            panic("reflect: slice index out of range")
        }

This was in prod so I'm not sure what the exact input was, but let me know if there's anything else that would be relevant.

Thanks!