Repository navigation
buffer: throw on write() to immutable buffers - #67741
Open
vedchaudhari wants to merge 1 commit into
Open
vedchaudhari wants to merge 1 commit into
vedchaudhari wants to merge 1 commit into
Conversation
buf.write() could change the bytes of a buffer backed by an immutable ArrayBuffer. Throw ERR_INVALID_ARG_VALUE instead, like other APIs already do. Refs: nodejs#66346 Signed-off-by: vedchaudhari <vedc2853@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67741 +/- ##
==========================================
- Coverage 90.54% 90.52% -0.02%
==========================================
Files 803 803
Lines 285094 285106 +12
Branches 55024 55032 +8
==========================================
- Hits 258133 258098 -35
- Misses 17105 17140 +35
- Partials 9856 9868 +12
🚀 New features to boost your workflow:
|
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.
buf.write()and the encoding-specific write methods (utf8Write(),hexWrite(), etc.) write into buffers backed by an immutable ArrayBuffer:buf.fill(),buf.set()and thewriteUInt*()methods already throw here.This adds the check to the three native write paths, including the fast API one, and throws
ERR_INVALID_ARG_VALUElikecrypto.randomFillSync()does (#66944). Invalid arguments are still reported first, and zero-byte writes throw too, like TypedArray methods.SPREAD_BUFFER_ARGnow keeps theArrayBufferit already fetches, so the check doesn't need a secondBuffer()call. With that, thebuffers/buffer-write-string*benchmarks are about -1% on average, and at most about -3.5% for 1-32 byte writes.Refs: #66346
Assisted-by: an AI coding agent. Reviewed and tested locally by me.
cc @jasnell @panva