vfs: MemoryProvider.setReadOnly() does not prevent writes through existing file descriptors
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, node.js
- Ambito
- operating-systems
Direzione di ricerca
Inizia con i percorsi indicati MemoryProvider.openSync(), MemoryFileHandle, VirtualFileSystem.writeSync() e ftruncateSync(), quindi esegui la riproduzione fornita con --experimental-vfs. Il lavoro è completato quando le scritture e i troncamenti tramite descrittori aperti prima di setReadOnly() generano EROFS, mentre il comportamento esistente basato sui percorsi rimane intatto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version
latest main branch
Platform
7.1.2-arch3-1
Subsystem
vfs
What steps will reproduce the bug?
const vfs = require('node:vfs');
const provider = new vfs.MemoryProvider();
const virtualFs = vfs.create(provider, {
emitExperimentalWarning: false,
});
virtualFs.writeFileSync('/file.txt', 'old');
const fd = virtualFs.openSync('/file.txt', 'r+');
provider.setReadOnly();
const data = Buffer.from('new');
virtualFs.writeSync(fd, data, 0, data.length, 0);
console.log(virtualFs.readFileSync('/file.txt', 'utf8')); // "new"
virtualFs.closeSync(fd);
Run with:
node --experimental-vfs reproduction.js
How often does it reproduce? Is there a required condition?
It reproduces consistently.
The writable file descriptor must be opened before setReadOnly() is called. Opening a new writable descriptor after setReadOnly() correctly throws EROFS.
What is the expected behavior? Why is that the expected behavior?
Once setReadOnly() has been called, subsequent writes through any VirtualFileSystem backed by that provider should throw an error with code === 'EROFS', including writes through file descriptors that were opened before the provider became read-only.
This follows the current documentation for MemoryProvider.setReadOnly():
Subsequent writes through any VirtualFileSystem using this provider throw EROFS.
ftruncateSync() through an existing writable descriptor should similarly throw EROFS.
What do you see instead?
writeSync() succeeds and modifies the file even though:
virtualFs.readonly === true
ftruncateSync() also succeeds through a descriptor opened before setReadOnly().
Additional information
MemoryProvider.openSync() checks provider.readonly when a writable handle is opened. However, an existing MemoryFileHandle does not retain or re-check the provider's read-only state.
File-descriptor operations such as VirtualFileSystem.writeSync() and ftruncateSync() operate directly on the stored handle, so they bypass the provider's current readonly value.
Path-based writes made after setReadOnly(), such as writeFileSync(), already throw EROFS as expected.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.4k
- Merge medio
- 4g 3h
- PR unite (30g)
- 273
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node
-
doc
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
build
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
Edit: CW+ Apertachannels:edit check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
idean3885/claude-ops-agent#521 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
avniproject/avni-client#2135 ·
-
automated broken-link
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100