Skip to content

vfs: avoid recursive readdir symlink cycles#64168

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-vfs-readdir-symlink-cycle
Open

vfs: avoid recursive readdir symlink cycles#64168
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-vfs-readdir-symlink-cycle

Conversation

@mcollina

@mcollina mcollina commented Jun 27, 2026

Copy link
Copy Markdown
Member

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.js
  • git rev-parse HEAD~0 | xargs npx -q core-validate-commit --no-validate-metadata --tap

Note: A full local rebuild was not completed in this environment; CI is building and running the test with the rebuilt binary.

@mcollina mcollina added the vfs Issues and PRs related to the virtual filesystem subsystem. label Jun 27, 2026
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 27, 2026

@jasnell jasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@mcollina mcollina force-pushed the fix-vfs-readdir-symlink-cycle branch from a6d70da to a918cd8 Compare June 27, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:vfs MemoryProvider: readdirSync({recursive:true}) crashes via circular symlinks (stack overflow)

3 participants