Skip to content

buffer: fix negative index for large buffers - #66325

Open
Dansatch wants to merge 1 commit into
nodejs:mainfrom
Dansatch:fix-buffer-indexof-2gib
Open

Dansatch wants to merge 1 commit into
nodejs:mainfrom
Dansatch:fix-buffer-indexof-2gib

Conversation

@Dansatch

Copy link
Copy Markdown

Fixes #66294.

Buffer.prototype.indexOf() returned a negative position when a match occurred beyond 2 GiB because the result was converted to a signed 32-bit integer.

This change returns the position as a JavaScript number and adds regression tests for number, Buffer, and string searches.

@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 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Fix incorrect negative index results for large buffers.
Add tests for number, Buffer and string searches beyond 2 GiB.

Fixes: nodejs#66294

Signed-off-by: dansatch <dansatch98@gmail.com>
@Dansatch
Dansatch force-pushed the fix-buffer-indexof-2gib branch from d1a0f65 to 04a1fd7 Compare September 26, 2026 18:00
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.37%. Comparing base (c0681e5) to head (04a1fd7).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/node_buffer.cc 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66325      +/-   ##
==========================================
- Coverage   90.37%   90.37%   -0.01%     
==========================================
  Files         790      790              
  Lines      274514   274514              
  Branches    52572    52570       -2     
==========================================
- Hits       248102   248089      -13     
- Misses      16889    16921      +32     
+ Partials     9523     9504      -19     
Files with missing lines Coverage Δ
src/node_buffer.cc 70.33% <80.00%> (-0.09%) ⬇️

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

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.

Buffer.prototype.indexOf returns a negative (int32-wrapped) position for matches beyond 2 GiB

2 participants