Skip to content

fix: ensure valid indexing of arguments array - #15922

Merged
kgryte merged 2 commits into
stdlib-js:developfrom
manit2004:fix/utils-pick-mask-arguments-nary
Oct 12, 2026
Merged

kgryte merged 2 commits into
stdlib-js:developfrom
manit2004:fix/utils-pick-mask-arguments-nary

Conversation

@manit2004

Copy link
Copy Markdown
Contributor

Resolves #15921

Description

What is the purpose of this pull request?

This pull request:

  • Fixes mask-arguments and pick-arguments, which both fall back to a generic loop (nary()) once 6 or more argument positions are selected. That loop looped arguments.length times instead of idx.length times; i.e. it used "how many arguments the wrapper happens to be called with" instead of "how many positions were actually selected." Calling the wrapper with more arguments than positions selected leaked extra stray undefineds through to the wrapped function. Adds regression tests covering both the more-args-than-selected and fewer-args-than-selected cases, since the existing nary tests always happened to call with exactly as many arguments as positions selected, which is why this went unnoticed.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • None

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Repro:

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

function foo() {
    return arguments.length;
}

var bar = pickArguments( foo, [ 0, 1, 2, 3, 4, 5 ] );

bar( 1, 2, 3, 4, 5, 6, 7, 8 ); // returned 8, now returns 6

Verified both fixes against the exact repro (before: 8/7, after: 6/6 for pick-arguments/mask-arguments respectively), and confirmed the new tests fail on the unfixed code and pass on the fixed code.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@manit2004
manit2004 requested a review from a team October 5, 2026 19:15
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Oct 5, 2026
@manit2004 manit2004 changed the title Fix/utils pick mask arguments nary Fix(utils pick mask arguments nary Oct 5, 2026
@manit2004 manit2004 changed the title Fix(utils pick mask arguments nary Fix(utils): pick/mask arguments nary loop Oct 5, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
utils/mask-arguments $\\color{green}207/207$
$\\color{green}+100.00\\%$
$\\color{green}20/20$
$\\color{green}+100.00\\%$
$\\color{green}8/8$
$\\color{green}+100.00\\%$
$\\color{green}207/207$
$\\color{green}+100.00\\%$
utils/pick-arguments $\\color{green}207/207$
$\\color{green}+100.00\\%$
$\\color{green}21/21$
$\\color{green}+100.00\\%$
$\\color{green}8/8$
$\\color{green}+100.00\\%$
$\\color{green}207/207$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@manit2004 manit2004 changed the title Fix(utils): pick/mask arguments nary loop fix(utils): pick/mask arguments nary loop Oct 5, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Oct 12, 2026

@kgryte kgryte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for fixing, @manit2004!

@kgryte kgryte changed the title fix(utils): pick/mask arguments nary loop fix: ensure valid indexing of arguments array Oct 12, 2026
@kgryte
kgryte merged commit ed03196 into stdlib-js:develop Oct 12, 2026
41 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants