vfs: avoid recursive readdir symlink cycles#64168
Open
mcollina wants to merge 1 commit into
Open
Conversation
jasnell
approved these changes
Jun 27, 2026
jasnell
left a comment
Member
There was a problem hiding this comment.
I think I'd much prefer to see if there's a way to make the walk iterative rather than recursive but this works.
Track the active MemoryProvider recursive readdir traversal path so circular symlinks to directories stop recursing while still listing the symlink entries. Add sync, promise, and withFileTypes coverage. Fixes: nodejs#64148 Signed-off-by: Matteo Collina <hello@matteocollina.com>
a6d70da to
a918cd8
Compare
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.
Fixes: #64148
MemoryProvider recursive readdir follows symlinked directories, but circular symlinks could recurse until the stack overflowed. This tracks the active traversal path so cycles are skipped while symlink entries are still listed.
Added regression coverage for sync, promise, mutual-cycle, and withFileTypes recursive readdir cases.
Tests:
git diff --check./node tools/eslint/node_modules/eslint/bin/eslint.js --max-warnings=0 --report-unused-disable-directives lib/internal/vfs/providers/memory.js test/parallel/test-vfs-readdir-symlink-recursive.js./node --experimental-vfs --expose-internals /tmp/test-vfs-memory-provider-source-wrapper.jsgit rev-parse HEAD~0 | xargs npx -q core-validate-commit --no-validate-metadata --tapNote: A full local rebuild was not completed in this environment; CI is building and running the test with the rebuilt binary.