Skip to content

buffer: fix odd UTF-16LE indexOf start - #65960

Open
inoway46 wants to merge 1 commit into
nodejs:mainfrom
inoway46:fix-utf16le-indexof-start-offset
Open

inoway46 wants to merge 1 commit into
nodejs:mainfrom
inoway46:fix-utf16le-indexof-start-offset

Conversation

@inoway46

@inoway46 inoway46 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

An odd forward UTF-16LE/UCS2 search start was rounded down, allowing a match before the requested start.
Round it up to the next UTF-16 code-unit boundary instead.

This preserves the existing code-unit-aligned string search semantics. It does not introduce every-byte-offset or cross-code-unit matches, or change Buffer/Uint8Array needle behavior.
Unaligned receivers are tracked separately in #65959.

Fixes: #26448

@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 Sep 10, 2026
@inoway46
inoway46 marked this pull request as ready for review September 10, 2026 12:13
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.18%. Comparing base (b805fb5) to head (045fc67).
⚠️ Report is 72 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65960   +/-   ##
=======================================
  Coverage   90.17%   90.18%           
=======================================
  Files         771      771           
  Lines      265489   265493    +4     
  Branches    50471    50471           
=======================================
+ Hits       239405   239425   +20     
+ Misses      17042    17007   -35     
- Partials     9042     9061   +19     
Files with missing lines Coverage Δ
src/node_buffer.cc 69.59% <100.00%> (+0.28%) ⬆️

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

UTF-16LE string searches rounded odd forward start offsets down,
allowing a match before the requested range.

Round the start up to the next code-unit boundary while leaving
reverse search and the existing 16-bit implementation unchanged.

Assisted-by: Codex
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
@inoway46
inoway46 force-pushed the fix-utf16le-indexof-start-offset branch from 128a78b to 045fc67 Compare September 10, 2026 14:28
@inoway46 inoway46 added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 14, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 14, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. 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.

buffer.indexOf is incorrect in utf16le encoding for odd byteOffset

4 participants