Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug/elf: unexpected EOF when read data of bss section #46414

Closed
qingyunha opened this issue May 27, 2021 · 3 comments
Closed

debug/elf: unexpected EOF when read data of bss section #46414

qingyunha opened this issue May 27, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@qingyunha
Copy link
Contributor

qingyunha commented May 27, 2021

What version of Go are you using (go version)?

$ go version
go version go1.13.12 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY=""
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build669194945=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"debug/elf"
)

func main() {
	f, _ := elf.Open("/bin/ls")
	for _, s := range f.Sections {
		if s.Name == ".bss" {
			if _, err := s.Data(); err != nil {
				panic(err)
			}
		}
	}
}

What did you expect to see?

no panic

What did you see instead?

panic: unexpected EOF

@qingyunha
Copy link
Contributor Author

elf(5) says A section of type SHT_NOBITS may have a nonzero size, but it occupies no space in the file.

p.sr = io.NewSectionReader(r, int64(p.Off), int64(p.Filesz))
The above code not handle this case.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 27, 2021
@mknyszek mknyszek added this to the Backlog milestone May 27, 2021
@mknyszek
Copy link
Contributor

IIRC the debug/elf package isn't necessarily intended to support everything that the ELF spec supports (then again, I may be thinking of debug/dwarf...). I don't think we wouldn't accept a patch that extends the package to support more of ELF, but if what I say is true, then I'm not sure we're going to work on fixing it necessarily.

All of this could be wrong though, so I defer to the owner, @ianlancetaylor via https://dev.golang.org/owners.

@seankhliao
Copy link
Member

Duplicate of #18667

@seankhliao seankhliao marked this as a duplicate of #18667 May 27, 2021
@golang golang locked and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants