Skip to content

src: fix out-of-bounds write in ucs2 encode of unaligned buffer#64697

Open
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ucs2-encode-unaligned-overflow
Open

src: fix out-of-bounds write in ucs2 encode of unaligned buffer#64697
Nashit-h wants to merge 1 commit into
nodejs:mainfrom
Nashit-h:ucs2-encode-unaligned-overflow

Conversation

@Nashit-h

Copy link
Copy Markdown

StringBytes::Encode decodes a ucs2 slice whose data pointer is 2-byte unaligned through a branch that allocates buflen/2 code units but memcpy's the full byte length, so an odd-length slice at an odd start offset (reachable from Buffer.prototype.toString('ucs2', start, end)) writes one byte past the destination. Copy only whole code units so the copy matches the allocation and the aligned path, which already drops the trailing odd byte.

@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 Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (0992f6b) to head (c80bd07).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64697   +/-   ##
=======================================
  Coverage   90.14%   90.14%           
=======================================
  Files         741      741           
  Lines      242112   242158   +46     
  Branches    45605    45610    +5     
=======================================
+ Hits       218244   218295   +51     
+ Misses      15360    15346   -14     
- Partials     8508     8517    +9     
Files with missing lines Coverage Δ
src/string_bytes.cc 73.55% <100.00%> (ø)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants