Skip to content

buffer: fill ignores an explicit end when offset is undefined #67574

Open

Description

@archidoge0

Version

Node.js v24.22.2, v26.13.0 and v26.13.1

Platform

macOS 15.2, Darwin 24.2.0, arm64.

Subsystem

buffer

What steps will reproduce the bug?

Save as repro.cjs:

for (const value of [1, 'a', Buffer.from([7])]) {
  console.log('undefined offset:', Buffer.alloc(4).fill(value, undefined, 2));
  console.log('zero offset:', Buffer.alloc(4).fill(value, 0, 2));
}

Run:

node repro.cjs

How often does it reproduce? Is there a required condition?

Every run when offset is undefined and end is explicitly supplied. The example uses number, string and Buffer fill values.

What is the expected behavior? Why is that the expected behavior?

undefined offset: <Buffer 01 01 00 00>
zero offset: <Buffer 01 01 00 00>
undefined offset: <Buffer 61 61 00 00>
zero offset: <Buffer 61 61 00 00>
undefined offset: <Buffer 07 07 00 00>
zero offset: <Buffer 07 07 00 00>

The buf.fill documentation gives offset a default of 0 and defines end as the exclusive stopping position. Defaulting offset should preserve the explicitly supplied end, giving the same result as offset=0.

What do you see instead?

The listed versions produce:

undefined offset: <Buffer 01 01 01 01>
zero offset: <Buffer 01 01 00 00>
undefined offset: <Buffer 61 61 61 61>
zero offset: <Buffer 61 61 00 00>
undefined offset: <Buffer 07 07 07 07>
zero offset: <Buffer 07 07 00 00>

Additional information

In _fill, the undefined-offset branches set both offset=0 and end=buf.length. The reproduction keeps end within bounds to isolate this behavior.

AI tools assisted with analysis and preparation of this report and its reproduction. A human has reviewed and confirmed the issue and verified that it is reproducible.

Credit: UCSB PLSE — https://ucsbplse.github.io/

Activity

  1. inoway46 commented on Nov 22, 2026

    @inoway46
    Contributor

    Reproduced on main (v28.0.0-pre), v26.13.1, and v24.22.3 (macOS arm64).

  2. added
    bufferIssues and PRs related to the buffer subsystem.
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions