Skip to content

buffer: fix end parameter bugs in indexOf/lastIndexOf#62711

Open
ronag wants to merge 1 commit intonodejs:mainfrom
ronag:buffer-index-of-end2
Open

buffer: fix end parameter bugs in indexOf/lastIndexOf#62711
ronag wants to merge 1 commit intonodejs:mainfrom
ronag:buffer-index-of-end2

Conversation

@ronag
Copy link
Copy Markdown
Member

@ronag ronag commented Apr 12, 2026

  • Fix FastIndexOfNumber parameter order mismatch (end_i64 and is_forward were swapped vs the JS call site and slow path)
  • Clamp negative end values to 0 to prevent size_t overflow in IndexOfString, IndexOfBuffer, and IndexOfNumberImpl
  • Clamp empty needle result to search_end

Fixes: #62873

@ronag ronag requested review from jasnell and mcollina April 12, 2026 20:18
@ronag ronag added the buffer Issues and PRs related to the buffer subsystem. label Apr 12, 2026
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Apr 12, 2026
@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 12, 2026
@ronag ronag force-pushed the buffer-index-of-end2 branch 2 times, most recently from 81afd27 to 927c25a Compare April 12, 2026 20:28
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (4563cb3) to head (7d46b35).
⚠️ Report is 84 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62711      +/-   ##
==========================================
+ Coverage   88.93%   89.62%   +0.69%     
==========================================
  Files         699      706       +7     
  Lines      216379   219169    +2790     
  Branches    41281    41994     +713     
==========================================
+ Hits       192434   196438    +4004     
+ Misses      15976    14619    -1357     
- Partials     7969     8112     +143     
Files with missing lines Coverage Δ
src/node_buffer.cc 68.72% <100.00%> (+0.69%) ⬆️

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

@ronag ronag requested a review from ChALkeR April 21, 2026 15:24
- Fix FastIndexOfNumber parameter order mismatch (end_i64 and
  is_forward were swapped vs the JS call site and slow path)
- Clamp negative end values to 0 to prevent size_t overflow in
  IndexOfString, IndexOfBuffer, and IndexOfNumberImpl
- Clamp empty needle result to search_end

Signed-off-by: Robert Nagy <ronagy@icloud.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ronag ronag force-pushed the buffer-index-of-end2 branch from 927c25a to 7d46b35 Compare April 21, 2026 23:47
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. request-ci Add this label to start a Jenkins CI on a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OOB read in Buffer.prototype.indexOf

2 participants