Skip to content

fs: validate mode as Int32 in ReadStream/WriteStream constructors - #62538

Closed
wdskuki wants to merge 1 commit into
nodejs:mainfrom
wdskuki:fix-fs-stream-mode-validation-regression
Closed

wdskuki wants to merge 1 commit into
nodejs:mainfrom
wdskuki:fix-fs-stream-mode-validation-regression

Conversation

@wdskuki

@wdskuki wdskuki commented Apr 1, 2026

Copy link
Copy Markdown

Fixes a regression where passing a mode value that exceeds Int32 max (but is within UInt32 range) to createWriteStream or createReadStream would cause an assertion failure crash instead of throwing a catchable RangeError.

The issue was introduced when mode validation was moved from JS to C++, but the ReadStream/WriteStream constructors were not updated to validate the mode option before passing it to the C++ layer.

Changes

Testing

  • Added test/parallel/test-fs-stream-mode-validation.js
  • Verified fix prevents crash and throws proper RangeError

Fixes: #62516

Fixes a regression where passing a mode value that exceeds Int32 max
(but is within UInt32 range) to createWriteStream or createReadStream
would cause an assertion failure crash instead of throwing a catchable
RangeError.

The issue was introduced when mode validation was moved from JS to C++,
but the ReadStream/WriteStream constructors were not updated to validate
the mode option before passing it to the C++ layer.

Changes:
- Import and use parseFileMode in lib/internal/fs/streams.js for both
  ReadStream and WriteStream constructors
- Change parseFileMode in lib/internal/validators.js to use validateInt32
  instead of validateUint32 to match C++ expectations
- Add regression test for issue nodejs#62516

Fixes: nodejs#62516
PR-URL: TBD
Reviewed-By: TBD
@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 Apr 1, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

@github-actions github-actions Bot closed this Aug 27, 2026
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. stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing large value for mode option in fs.createWriteStream results in crash

2 participants