Repository navigation
fs: validate opendir() bufferSize before opening the directory - #67183
Open
yohannesjoya wants to merge 1 commit into
Open
yohannesjoya wants to merge 1 commit into
yohannesjoya wants to merge 1 commit into
Conversation
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]>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fs.opendir()only validatedoptions.bufferSizein theDirconstructor, which runs from the completion callback of the nativeopendircall. An invalid value was thrown from there, so notry/catchcould catch it, the callback was never called, and the process exited.fs.promises.opendir()ispromisify(opendir)and had the same problem.This checks
bufferSizebefore the native call, sofs.opendir()throws to the caller andfs.promises.opendir()rejects.fs.opendirSync()is unchanged, and the check in theDirconstructor stays for it. An explicitbufferSize: undefinedis still rejected, as before.Fixes: #67182
The new test fails on main and passes with this change.
tools/test.pyforparallel/test-fs-opendir*,parallel/test-fs-*dir*andparallel/test-fs-promises*(91 tests) andmake lint-jspass 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.