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

io/fs: SubFS.Open returns incorrect errors for invalid paths #65419

Closed
paulhammond opened this issue Feb 1, 2024 · 5 comments
Closed

io/fs: SubFS.Open returns incorrect errors for invalid paths #65419

paulhammond opened this issue Feb 1, 2024 · 5 comments
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@paulhammond
Copy link

Go version

go version go1.21.1 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/vscode/.cache/go-build'
GOENV='/home/vscode/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY='github.com/paulhammond'
GONOSUMDB='github.com/paulhammond'
GOOS='linux'
GOPATH='/go'
GOPRIVATE='github.com/paulhammond'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/workspace/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2551620224=/tmp/go-build -gno-record-gcc-switches'

What did you do?

The documentation for the fs.FS interface says:

Open should reject attempts to open names that do not satisfy ValidPath(name), returning a *PathError with Err set to ErrInvalid or ErrNotExist.

The errors returned by SubFS.Open() do not fulfill this contract, as demonstrated by https://go.dev/play/p/N5lvehlpeB5. Calling Open with an invalid path returns a *PathError with Err set to errors.New("invalid name") instead. This breaks any code that accepts an fs.FS and attempts to handle the documented errors.

What did you see happen?

err open ./: invalid name
isInvalid false
isNotExist false

What did you expect to see?

err open ./: invalid argument
isInvalid true
isNotExist false
@panjf2000 panjf2000 added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 1, 2024
@panjf2000 panjf2000 self-assigned this Feb 1, 2024
@gopherbot
Copy link

Change https://go.dev/cl/560137 mentions this issue: io/fs: set ErrInvalid for FS.Open from SubFS when it fails ValidPath

@panjf2000 panjf2000 added this to the Go1.23 milestone Feb 1, 2024
@Nytonecombek

This comment has been minimized.

@Nytonecombek

This comment has been minimized.

@Nytonecombek

This comment has been minimized.

@Nytonecombek

This comment has been minimized.

@Nytonecombek Nytonecombek mentioned this issue Feb 1, 2024
2 tasks
@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Feb 10, 2024
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
Fixes golang#65419

Change-Id: I8f9f82ab0387d8bb39aaca4f9e60e36ee15c587d
Reviewed-on: https://go-review.googlesource.com/c/go/+/560137
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants