vfs: MemoryProvider.setReadOnly() does not prevent writes through existing file descriptors
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với các đường dẫn được nêu tên là MemoryProvider.openSync(), MemoryFileHandle, VirtualFileSystem.writeSync() và ftruncateSync(), sau đó chạy bản tái hiện được cung cấp với --experimental-vfs. Được xem là hoàn tất khi các thao tác ghi và cắt ngắn thông qua các descriptor được mở trước setReadOnly() ném EROFS, trong khi hành vi dựa trên đường dẫn hiện có vẫn được giữ nguyên.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 68/100