Skip to content

vfs: enforce readonly state on open handles#64403

Open
harjothkhara wants to merge 1 commit into
nodejs:mainfrom
harjothkhara:codex/fix-vfs-readonly-handles
Open

vfs: enforce readonly state on open handles#64403
harjothkhara wants to merge 1 commit into
nodejs:mainfrom
harjothkhara:codex/fix-vfs-readonly-handles

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jul 10, 2026

Copy link
Copy Markdown

MemoryProvider.setReadOnly() prevented new writable handles from being opened,
but handles opened before the transition retained write access. This allowed
descriptor-based writes and truncation to bypass the provider's documented
read-only state.

Pass a live provider-state callback to MemoryFileHandle and check it at each
mutation primitive. This covers descriptor and direct-handle operations,
including delegated async, vector, and append-mode writes, while preserving
EBADF precedence for handles that were not opened for writing.

Regression tests cover:

  • writeSync() and ftruncateSync() through pre-existing descriptors
  • append-mode descriptors opened before setReadOnly()
  • async handle write(), writeFile(), truncate(), and writev()
  • unchanged file contents after rejected mutations

Validation:

  • python3 tools/test.py test/parallel/test-vfs-memory-provider.js test/parallel/test-vfs-memory-file-handle.js
  • JavaScript lint on the three changed files

Fixes: #64401

Signed-off-by: harjoth <harjoth.khara@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Jul 10, 2026
@harjothkhara harjothkhara marked this pull request as ready for review July 10, 2026 05:20
@harjothkhara

harjothkhara commented Jul 10, 2026

Copy link
Copy Markdown
Author

Tested this end to end.

Before the fix: the example from #64401 still writes to the file after it's set read-only — bug confirmed.

After the fix: that write is blocked with EROFS, the file is unchanged, and the new test passes. All 97 vfs tests pass and lint is clean.

Other write paths (truncate, append, write streams) are blocked too, and read-only handles still give the original EBADF.

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.

vfs: MemoryProvider.setReadOnly() does not prevent writes through existing file descriptors

2 participants