Repository navigation
fs: reject a mode above INT32_MAX instead of aborting - #67498
Open
yohannesjoya wants to merge 1 commit into
Open
yohannesjoya wants to merge 1 commit into
yohannesjoya wants to merge 1 commit into
Conversation
parseFileMode() accepted any 32-bit unsigned integer, but the native bindings read the mode as a signed 32-bit integer and CHECK that it is one. A mode between 2**31 and 2**32 - 1 therefore passed validation and then aborted the process from fs.open(), fs.chmod(), fs.mkdir() and their sync and promise variants. Validate the mode as a non-negative Int32 instead so that the caller gets a RangeError. ReadStream and WriteStream now validate options.mode in the constructor too, so an invalid mode throws where the stream is created instead of failing inside the open callback. Fixes: nodejs#62516 Refs: nodejs#62538 Co-authored-by: wei_ds <wei_ds@126.com> Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67498 +/- ##
==========================================
- Coverage 92.99% 90.67% -2.32%
==========================================
Files 428 799 +371
Lines 195633 280245 +84612
Branches 30281 54115 +23834
==========================================
+ Hits 181937 254125 +72188
- Misses 13369 16238 +2869
- Partials 327 9882 +9555
🚀 New features to boost your workflow:
|
jasnell
approved these changes
Nov 15, 2026
Collaborator
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.
A
modebetween 2³¹ and 2³²−1 passesparseFileMode()(it validates as Uint32) but the C++ bindingsCHECKfor an Int32, so the process aborts withAssertion failed: args[2]->IsInt32(). This affectsfs.open(),fs.openSync(),fs.promises.open(),fs.chmod(),fs.mkdir()and the stream constructors. Reproduced on main withfs.openSync('f', 'w', 0x80000000).This validates the mode as a non-negative Int32, so the caller gets a
RangeErrorwith the real limit.ReadStream/WriteStreamvalidateoptions.modein the constructor so the error is thrown where the stream is created. Two existing tests that asserted the old<= 4294967295message are updated, and a new test covers every affected API; it aborts on main and passes with this change.Credit: @semimikoh traced this to #52050 in the issue, and @wdskuki's #62538 had the same
validateInt32idea and the stream constructor change (carried here withCo-authored-by). The issue was closed by the stale bot; could a collaborator reopen it?Fixes: #62516
Refs: #62538
AI disclosure: I used a coding agent to help find the affected call sites and draft the test. I reproduced the abort on main, reviewed the change line by line, and ran the fs test suite locally.