Go version
go version go1.24.2 linux/amd64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build890824037=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10888'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10888/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
I attempted to automatically analyze the executables on a Windows host. As a part of that, debug/pe.File.ImportedSymbols()
was called.
This failed on the official Windows Word .exe file with a "slice bounds out of range" error.
https://go.dev/play/p/K1_mQcc4Fbd
Minimal example which produces the same error with just the first 32k bytes of winword.exe
.
If required, I can share the full file itself as well. Though I am not 100% sure about the licensing terms of sharing winword.exe
What did you see happen?
Slice bounds out of error panic, as is visible in the Go Playground link.
panic: runtime error: slice bounds out of range [4294947512:512]
goroutine 1 [running]:
debug/pe.(*File).ImportedSymbols(0x50a608?)
/usr/local/go-faketime/src/debug/pe/file.go:411 +0x949
main.main()
/tmp/sandbox1960551843/prog.go:16 +0x186
What did you expect to see?
A slice with the names of the symbols, as the documentation states.
Comment From: gabyhelp
Related Issues
- debug/elf: slice bounds out of range in Symbols #62649 (closed)
- debug/pe: attempt to allocate giant slice #17809 (closed)
- debug/pe: slice bounds out of range #30253 (closed)
- debug/pe: Calling File.ImportedLibraries returns an empty slice #48039
- debug/elf: slice bounds out of range #10999 (closed)
- debug/elf: slice out of bounds in ImportedLibraries #63610 (closed)
- debug/pe: TestInternalLinkerDWARF fail in windows #64200 (closed)
- x/tools/cmd/gopls: crashes with "slice bounds out of range" #31707 (closed)
- cmd/go: slice bounds out of range in test #14337 (closed)
- cmd/link: slice bounds out of range #62098 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: randall77
@alexbrainman @golang/windows
Comment From: monoidic
It does seem that a good number of PE parsers stumble a bit on this file, actually.
The Rust pelite library gives a "unaligned" error unless unsafe_alignment
is used, disabling alignment checks.
pestudio displays garbled text.
PE-Bear and the Python pefile
library seem to work just fine.
Comment From: gopherbot
Change https://go.dev/cl/684495 mentions this issue: debug/pe: avoid panic in File.ImportedSymbols
Comment From: alexbrainman
@monoidic please check if https://go.dev/cl/684495 fixes your problem.
Thank you.
Alex