Skip to content

fs: validate opendir() bufferSize before opening the directory - #67183

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-opendir-buffersize-crash
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-opendir-buffersize-crash

Conversation

@yohannesjoya

Copy link
Copy Markdown

fs.opendir() only validated options.bufferSize in the Dir constructor, which runs from the completion callback of the native opendir call. An invalid value was thrown from there, so no try/catch could catch it, the callback was never called, and the process exited. fs.promises.opendir() is promisify(opendir) and had the same problem.

This checks bufferSize before the native call, so fs.opendir() throws to the caller and fs.promises.opendir() rejects. fs.opendirSync() is unchanged, and the check in the Dir constructor stays for it. An explicit bufferSize: undefined is still rejected, as before.

Fixes: #67182

The new test fails on main and passes with this change. tools/test.py for parallel/test-fs-opendir*, parallel/test-fs-*dir* and parallel/test-fs-promises* (91 tests) and make lint-js pass locally.

AI disclosure: I used a coding agent to help find the bug and draft the test. I reproduced the crash on v20.20.2, v22.20.0 and main, reviewed the change line by line, and ran the tests above locally.

fs.opendir() only checked options.bufferSize in the Dir constructor,
which runs from the completion callback of the native opendir call.
An invalid value was thrown from there, so it could not be caught and
the process exited. fs.promises.opendir() is built on fs.opendir() and
had the same problem.

Check bufferSize before starting the native call, so fs.opendir()
throws to the caller and fs.promises.opendir() rejects.

Fixes: nodejs#67182
Signed-off-by: yohannesjoya <[email protected]>
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.opendir() and fs.promises.opendir() crash the process on an invalid bufferSize

2 participants