← Back to Pull requests

buffer: stop clamping indexOf byteOffset to int32 #67009

Closed
unknown closed this pull request without merging on Nov 16, 2026 10:17 UTC
View on GitHub
unknown unknown commented on Oct 26, 2026 04:35 UTC
Author

On buffers bigger than 2 GiB, indexOf(), lastIndexOf() and includes() change any byteOffset above 2 31 - 1 to 2 31 - 1, so the search starts in the wrong place:

const G = 2 ** 30;
const buf = Buffer.alloc(3 * G);
buf[2.25 * G] = 0x0a;
buf[2.75 * G] = 0x0a;

buf.indexOf(0x0a, 2.5 * G);     // main: 2415919104 (before the offset), this PR: 2952790016
buf.includes(0x0a, 2.9 * G);    // main: true, this PR: false
buf.lastIndexOf(0x0a, 2.6 * G); // main: -1, this PR: 2415919104

The int32 limit was added in 2016 (6c1e5ad3aba), when buffers couldn't be bigger than 2 GiB. MAX_LENGTH has grown a lot since v14, but the limit was never updated. The C++ side already uses 64-bit offsets, so I raised the limit to Number.MAX_SAFE_INTEGER, which still keeps values like Infinity out. The negative return values from the issue were already fixed by #66325.

The new cases in test/pummel/test-buffer-indexof-large.js fail on main and pass with this change. Results on normal-size buffers are unchanged.

Tested on macOS arm64.

Note: #66590 edits the same comment, so whichever lands second will need a small rebase.

Fixes: https://github.com/nodejs/node/issues/67008

Assisted-by: Claude. I reproduced the bug, reviewed the change and ran the tests myself.

<!--
If you are submitting a pull request for the first time,
check out the guide for first-time contributors for tips and answers to FAQs:
https://github.com/nodejs/node/blob/HEAD/doc/contributing/first-contributions.md

Before submitting a pull request, please read:

  • the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md

  • the commit message formatting guidelines at

  • https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

    For code changes:
    1. Include tests for any bug fixes or new features.
    2. Update documentation if relevant.
    3. Ensure that make -j4 test (UNIX), or vcbuild test (Windows) passes.

    If you believe this PR should be highlighted in the Node.js CHANGELOG
    please add the notable-change label.

    Developer's Certificate of Origin 1.1

    By making a contribution to this project, I certify that:

    (a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

    (b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

    (c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

    (d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
    -->

    Diff: 403 lines (+302 / -101) across 5 files Reviewer: ronag Review duration: 30581m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 403 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #67009"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.4% · Safe to merge
    19.4%
    Repository