GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: throw on write() to immutable buffers by vedchaudhari · Pull Request #67741 · nodejs/node

Conversation

@vedchaudhari

@vedchaudhari vedchaudhari commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

buf.write() and the encoding-specific write methods (utf8Write(), hexWrite(), etc.) write into buffers backed by an immutable ArrayBuffer:

// node --js-immutable-arraybuffer
const buf = Buffer.from(new Uint8Array([1, 2, 3, 4]).buffer.transferToImmutable());
buf.write('hi');
console.log(buf); // <Buffer 68 69 03 04>

buf.fill(), buf.set() and the writeUInt*() methods already throw here.

This adds the check to the three native write paths, including the fast API one, and throws ERR_INVALID_ARG_VALUE like crypto.randomFillSync() does (#66944). Invalid arguments are still reported first, and zero-byte writes throw too, like TypedArray methods.

SPREAD_BUFFER_ARG now keeps the ArrayBuffer it already fetches, so the check doesn't need a second Buffer() call. With that, the buffers/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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (fa49b13) to head (36f339b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/node_buffer.cc 83.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67741      +/-   ##
==========================================
- Coverage   92.59%   90.50%   -2.10%     
==========================================
  Files         433      805     +372     
  Lines      200382   285818   +85436     
  Branches    30786    55189   +24403     
==========================================
+ Hits       185553   258685   +73132     
- Misses      14486    17219    +2733     
- Partials      343     9914    +9571     
Files with missing lines Coverage Δ
src/util.h 90.84% <ø> (ø)
src/node_buffer.cc 75.51% <83.33%> (ø)

... and 514 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Nov 24, 2026

Copy link
Copy Markdown
Member

You'll probably want to rebase this after #67733 lands

vedchaudhari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vedchaudhari
buffer: throw on write() to immutable buffers
36f339b
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 <[email protected]>
@vedchaudhari
vedchaudhari force-pushed the buffer-write-immutable branch from 2053ed6 to 36f339b Compare November 26, 2026 08:44
@vedchaudhari

vedchaudhari commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

You'll probably want to rebase this after #67733 lands

Rebased on top of #67733.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Nov 26, 2026
View reviewed changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vedchaudhari @addaleax @jasnell @nodejs-github-bot
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.