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
Contributor

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
Contributor 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.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.24%. Comparing base (8fec65d) to head (78a5dec).
⚠️ Report is 155 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64403      +/-   ##
==========================================
- Coverage   90.25%   90.24%   -0.02%     
==========================================
  Files         741      741              
  Lines      241207   241225      +18     
  Branches    45430    45440      +10     
==========================================
- Hits       217698   217683      -15     
- Misses      15084    15121      +37     
+ Partials     8425     8421       -4     
Files with missing lines Coverage Δ
lib/internal/vfs/file_handle.js 98.90% <100.00%> (+0.01%) ⬆️
lib/internal/vfs/providers/memory.js 95.04% <100.00%> (+0.04%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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