Skip to content

[BUG]: mask-arguments/pick-arguments leak extra stray arguments in the n-ary (6+) fallback #15921

Closed

Description

@manit2004

Description

Both mask-arguments and pick-arguments fall back to a generic loop (nary()) once you're selecting 6+ argument positions. That loop's bound is wrong; it uses arguments.length (how many args the wrapper happens to get called with) instead of idx.length (how many positions were actually selected). Call it with more arguments than positions selected, and it leaks extra stray undefineds through to the wrapped function. Existing tests missed it because the one test hitting this path always called with exactly as many arguments as positions selected, masking the bug.

Related Issues

None

Questions

No.

Demo

No response

Reproduction

var pickArguments = require( '@stdlib/utils/pick-arguments' );

function foo() {
    return arguments.length;
}

var bar = pickArguments( foo, [ 0, 1, 2, 3, 4, 5 ] ); // 6 positions -> hits nary

bar( 1, 2, 3, 4, 5, 6, 7, 8 ); // should return 6, returns 8

Same thing with maskArguments:

var maskArguments = require( '@stdlib/utils/mask-arguments' );

var bar = maskArguments( foo, [ 1, 1, 1, 1, 1, 1, 0 ] ); // 6 masked-in positions

bar( 1, 2, 3, 4, 5, 6, 7 ); // should return 6, returns 7

Expected Results

`6` in both cases — only the selected/masked-in positions get forwarded, regardless of how many extra arguments the wrapper is called with.

Actual Results

`8` and `7` — extra stray `undefined`s get forwarded along with the real values.

Version

0.4.1

Environments

Node.js

Browser Version

No response

Node.js / npm Version

No response

Platform

Linux

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.

Activity

  1. changed the title [-]`mask-arguments`/`pick-arguments` leak extra stray arguments in the n-ary (6+) fallback[/-] [+][BUG]: `mask-arguments`/`pick-arguments` leak extra stray arguments in the n-ary (6+) fallback[/+] on Oct 12, 2026
  2. added
    BugSomething isn't working.
    priority: HighHigh priority concern or feature request.
    on Oct 12, 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

    BugSomething isn't working.priority: HighHigh priority concern or feature request.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions