Skip to content

buffer: reject swaps on immutable arraybuffers - #67392

Open
fatihguzeldev wants to merge 1 commit into
nodejs:mainfrom
fatihguzeldev:buffer-swap-immutable
Open

fatihguzeldev wants to merge 1 commit into
nodejs:mainfrom
fatihguzeldev:buffer-swap-immutable

Conversation

@fatihguzeldev

Copy link
Copy Markdown
Contributor

small immutable buffers throw in swap16(), swap32() and swap64().
larger buffers use native code, where the immutable check is missing.

add that check and let javascript throw the error when the native call
returns false. prepare the backing buffer before entering native code
to avoid allocation inside fast api callbacks.

refs: #66346

reject immutable backing stores in the native swap16, swap32 and swap64
paths instead of modifying their bytes. prepare backing buffers in
javascript and report errors after the native calls return.

Refs: nodejs#66346
Signed-off-by: Fatih Güzel <fatihguzeldev@gmail.com>
@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. typings Issues and PRs related to internal TypeScript declarations. labels Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.94118% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (6c8a697) to head (98b5d6a).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/node_buffer.cc 62.50% 0 Missing and 15 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67392      +/-   ##
==========================================
- Coverage   90.73%   90.72%   -0.01%     
==========================================
  Files         798      798              
  Lines      280076   280127      +51     
  Branches    53880    53901      +21     
==========================================
+ Hits       254123   254150      +27     
- Misses      16259    16273      +14     
- Partials     9694     9704      +10     
Files with missing lines Coverage Δ
lib/buffer.js 99.68% <100.00%> (+<0.01%) ⬆️
src/node_buffer.cc 75.00% <62.50%> (+0.13%) ⬆️

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

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

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. typings Issues and PRs related to internal TypeScript declarations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants