Repository navigation
memfs: Reject ReadDir calls on regular files - #247
Merged
Merged
Conversation
Returning an empty directory listing for a regular file hides invalid paths from callers and differs from the OS-backed filesystem. Check the target mode after resolving symlinks and return a PathError wrapping ENOTDIR. Add a shared filesystem regression and memfs coverage for symlinks to files and directories. Assisted-by: OpenAI Codex (GPT-6) Signed-off-by: Aryan <aryangupta050903@gmail.com>
pjbgf
approved these changes
Oct 16, 2026
pjbgf
left a comment
Member
There was a problem hiding this comment.
@Aryangupta-05 thank you for working on this. 🙇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
memfs.ReadDircurrently returns an empty result and no error for a regular file. Callers cannot distinguish that invalid directory path from an empty directory, unlike the OS-backed filesystem and the documentedbilly.Dircontract.Return a
*os.PathErrorwrappingsyscall.ENOTDIRafter resolving symlinks. The shared directory-conformance test compares the same call through memfs and osfs. A memfs regression also checks that a link to a file is rejected while a link to a directory remains readable.Minimal reproduction:
Before: empty entries, nil error. After: nil entries and a non-nil path error. The OS-backed regression passed before the change; the memfs and symlink-to-file regressions failed before and pass after.
Validation on Windows / Go 1.26.8:
go test ./memfs -count=1go test ./test -run '^TestDir_' -count=1go vet ./memfs ./test, gofmt andgit diff --check--new-from-rev=eae82c9f2d37fb502d080eef0ab6bc1655501985.Full-suite limitations were checked against a separate clean snapshot of the same upstream revision: both runs hit existing Windows symlink-privilege failures and the 45-second bound in the large TempFileMany stress test. Full lint reports unrelated findings in unchanged files on both snapshots; full vet flags the existing osfs.WriteTo signature. A full-suite pass or race-test pass is not claimed; the local C compiler could not start.
AI assistance: OpenAI Codex (GPT-6) assisted with investigation, implementation, regression tests, validation and this description. The commit includes an Assisted-by trailer and DCO sign-off.