Skip to content

net: reject immutable onread buffers - #67394

Open
fatihguzeldev wants to merge 1 commit into
nodejs:mainfrom
fatihguzeldev:net-onread-immutable
Open

fatihguzeldev wants to merge 1 commit into
nodejs:mainfrom
fatihguzeldev:net-onread-immutable

Conversation

@fatihguzeldev

Copy link
Copy Markdown
Contributor

socket reads can currently overwrite immutable storage passed
through onread.buffer, either directly or from a buffer factory.

reject these buffers before they are used for reads and report
ERR_INVALID_ARG_VALUE through the socket's error event.

refs: #66346

reject immutable buffers supplied directly or returned by an onread
buffer factory before using them for socket reads. emit
ERR_INVALID_ARG_VALUE without modifying the backing store.

Refs: nodejs#66346
Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.74%. Comparing base (2aef805) to head (ffac8fd).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/node_util.cc 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67394      +/-   ##
==========================================
- Coverage   90.74%   90.74%   -0.01%     
==========================================
  Files         798      798              
  Lines      280083   280119      +36     
  Branches    53900    53896       -4     
==========================================
+ Hits       254166   254195      +29     
+ Misses      16217    16211       -6     
- Partials     9700     9713      +13     
Files with missing lines Coverage Δ
lib/internal/stream_base_commons.js 95.28% <100.00%> (+0.42%) ⬆️
lib/net.js 94.97% <100.00%> (+0.19%) ⬆️
src/node_util.cc 81.77% <88.88%> (+0.17%) ⬆️

... and 33 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.

return req;
}

function onUserBufferError(stream, buffer) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name should be a bit specific....

Suggested change
function onUserBufferError(stream, buffer) {
function destroyWithImmutableArrayBufferError(stream, buffer) {

Comment thread lib/net.js
self[kBuffer] = userBuf;
}
self._handle.useUserBuffer(userBuf);
if (setUserBuffer(self, userBuf, true))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really not a fan of bool arguments, but if we're going to have them, please label call sites to make them clear (we're not consistent with that, at all... would love us to start)

Suggested change
if (setUserBuffer(self, userBuf, true))
if (setUserBuffer(self, userBuf, true /*deferError*/))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, is it mainly about readability at the call site, or are there other reasons you tend to avoid boolean parameters?

streamBaseState,
} = internalBinding('stream_wrap');
const { UV_EOF } = internalBinding('uv');
const { isArrayBufferViewImmutable } = internalBinding('util');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not available via primordials yet because it is flagged, but there is already an ArrayBuffer.prototype.immutable property that really should be used instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. i was able to deserialize an immutable arraybuffer with the flag off, but the getter isn't available there. would you recommend keeping the native check for that case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants