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

cmd/go,x/mod/module: missing exclusion for COM0, LPT0 for embedded file names #66625

Open
cookiengineer opened this issue Mar 31, 2024 · 1 comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@cookiengineer
Copy link

cookiengineer commented Mar 31, 2024

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/cookiengineer/.cache/go-build'
GOENV='/home/cookiengineer/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/cookiengineer/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/cookiengineer/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/cookiengineer/whatever/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2124737729=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I tried to embed a file called aux.json.gz on GNU/Linux:

//go:embed ./subfolder/aux.json.gz
var embedded_bytes []byte

What did you see happen?

Trying to embed files on GNU/Linux systems that have aux, (or con, nul, prn, com*, lpt*) as a basename of the file cannot be embedded via go:embed.

The reason is a call to isBadEmbedName() in the resolveEmbed() method in go/internal/load/pkg.go.

The isBadEmbedName() method leads to module.CheckFilePath(name) which compares the basename of the file to the badWindowsNames slice in module/module.go.

My questions are now the following:

  • Why is this the case on GNU/Linux systems?
  • Why does go:embed need valid filenames for go modules?
  • Why does go:embed need valid filenames for Windows? Is it unpacked temporarily when the binary is executed later, similar to squashfs, behind the scenes? Why is this not behind a host-specific tag?
  • If the decision is to keep the reserved basenames, COM0 and LPT0 are missing from that list. See the linked article from the module.go file.

What did you expect to see?

I expected to be able to embed filenames when they conform to the POSIX filesystem requirements, so I think it should be possible to embed filenames with the basename of con, prn, aux, nul, com*, lpt* etc.

@seankhliao seankhliao changed the title pattern <folder>/aux.json.gz: cannot embed file: invalid name cmd/go,x/mod/module: missing exclusion for COM0, LPT0 for embedded file names Mar 31, 2024
@seankhliao
Copy link
Member

we expect modules to be usable cross platform, so file name restrictions apply everywhere

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go 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

2 participants