Skip to content

Report too few builtin arguments in unchecked calls - #1025

Merged
antonmedv merged 4 commits into
masterfrom
fix-builtin-arity
Nov 25, 2026
Merged

antonmedv merged 4 commits into
masterfrom
fix-builtin-arity

Conversation

@antonmedv

@antonmedv antonmedv commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

The checker does not check the arguments of a call on an unknown value, so a builtin with too few arguments there, e.g. fn().N(join()), failed at run time with index out of range or stack underflow.

  • The compiler derives the minimum arity from the builtin's Types (and requires one argument for Fast builtins) and, when a call has too few, emits an OpThrow with invalid number of arguments for join (expected 1 or 2, got 0). Valid calls compile exactly as before.

  • Extra arguments of a Fast builtin in such a call were left on the stack and leaked into the enclosing expression (x + fn().N(upper("a", "b")) returned "aB"). They are now evaluated and popped; the builtin still gets the last argument, as before.

  • date(timezone("UTC")) passed the checker and panicked at run time. Validate now rejects it, and Func guards it for unchecked calls, as it does for date().

  • max, min, mean, median, first and last have no Types, and with no arguments quietly returned nil or 0. Their Func now returns the same invalid number of arguments error.

Extra arguments to Func/Safe builtins are still ignored: the generated corpus has working expressions that pass them ($env?.[first(0, ok)], toBase64(foobar) in a pipe), so rejecting them would break existing programs.

Based on #943 by @thevilledev, done in the compiler instead of per builtin.

Fixes #941

The checker does not check arguments of a call on an unknown value, so
fn().N(join()) panicked with index out of range or stack underflow.
Throw an invalid number of arguments error instead.

Based on #943. Fixes #941
date(timezone("UTC")) passed the checker and panicked at run time;
reject it in Validate and guard Func. Extra arguments of a Fast builtin
in an unchecked call stayed on the stack and leaked into the enclosing
expression; pop them. Name exact argument ranges in the arity error.
@antonmedv
antonmedv merged commit bd1338c into master Nov 25, 2026
22 checks passed
@antonmedv
antonmedv deleted the fix-builtin-arity branch November 25, 2026 08:52
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.

OSS-Fuzz issue 489360237

1 participant