ffi: reject non-boolean copy arguments - #66219
Closed
christianaurichzm wants to merge 1 commit into
Closed
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
ffi.toBuffer() and ffi.toArrayBuffer() document copy as a boolean, but read it with BooleanValue(), which applies JavaScript truthiness. A falsy non-boolean such as null, 0 or '' therefore selects the zero-copy mode, which returns a writable view over foreign memory instead of a copy, while values such as 'false' or 1 select a copy. Throw ERR_INVALID_ARG_TYPE when copy is neither undefined nor a boolean. Omitting copy or passing undefined still makes a copy, and true and false keep their current behavior. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66219 +/- ##
==========================================
- Coverage 90.29% 90.27% -0.02%
==========================================
Files 790 790
Lines 272883 272886 +3
Branches 52118 52105 -13
==========================================
- Hits 246387 246350 -37
- Misses 16943 16996 +53
+ Partials 9553 9540 -13
🚀 New features to boost your workflow:
|
daeyeon
approved these changes
Sep 25, 2026
Collaborator
panva
approved these changes
Sep 25, 2026
panva
pushed a commit
that referenced
this pull request
Sep 25, 2026
ffi.toBuffer() and ffi.toArrayBuffer() document copy as a boolean, but read it with BooleanValue(), which applies JavaScript truthiness. A falsy non-boolean such as null, 0 or '' therefore selects the zero-copy mode, which returns a writable view over foreign memory instead of a copy, while values such as 'false' or 1 select a copy. Throw ERR_INVALID_ARG_TYPE when copy is neither undefined nor a boolean. Omitting copy or passing undefined still makes a copy, and true and false keep their current behavior. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: #66219 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Member
|
Landed in 63a6ea2 |
aduh95
pushed a commit
that referenced
this pull request
Sep 27, 2026
ffi.toBuffer() and ffi.toArrayBuffer() document copy as a boolean, but read it with BooleanValue(), which applies JavaScript truthiness. A falsy non-boolean such as null, 0 or '' therefore selects the zero-copy mode, which returns a writable view over foreign memory instead of a copy, while values such as 'false' or 1 select a copy. Throw ERR_INVALID_ARG_TYPE when copy is neither undefined nor a boolean. Omitting copy or passing undefined still makes a copy, and true and false keep their current behavior. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: #66219 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
HoonDongKang
pushed a commit
to HoonDongKang/node
that referenced
this pull request
Sep 28, 2026
ffi.toBuffer() and ffi.toArrayBuffer() document copy as a boolean, but read it with BooleanValue(), which applies JavaScript truthiness. A falsy non-boolean such as null, 0 or '' therefore selects the zero-copy mode, which returns a writable view over foreign memory instead of a copy, while values such as 'false' or 1 select a copy. Throw ERR_INVALID_ARG_TYPE when copy is neither undefined nor a boolean. Omitting copy or passing undefined still makes a copy, and true and false keep their current behavior. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: nodejs#66219 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
Sep 28, 2026
ffi.toBuffer() and ffi.toArrayBuffer() document copy as a boolean, but read it with BooleanValue(), which applies JavaScript truthiness. A falsy non-boolean such as null, 0 or '' therefore selects the zero-copy mode, which returns a writable view over foreign memory instead of a copy, while values such as 'false' or 1 select a copy. Throw ERR_INVALID_ARG_TYPE when copy is neither undefined nor a boolean. Omitting copy or passing undefined still makes a copy, and true and false keep their current behavior. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: #66219 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
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.
ffi.toBuffer()andffi.toArrayBuffer()documentcopyas a boolean, but currently coerce other values throughBooleanValue().This means falsy values such as
null,0, and''select zero-copy mode instead of throwing:Truthy non-booleans such as
'false'and1are accepted as well and select the copy path.Reject non-boolean values with
ERR_INVALID_ARG_TYPE. Omittingcopyor passingundefinedstill defaults to copying, andtrueandfalsekeep their existing behavior.node:ffiis experimental and the documented type forcopyis{boolean}.Testing:
tools/test.py parallel sequential ffimake lintmake lint-cppmake format-cpp