Skip to content

Conversation

@thevilledev
Copy link
Contributor

Motivation

See OSS-Fuzz finding #903. The expression $env(''matches' '? :now().UTC(g).d)// caused:

runtime error: index out of range [0] with length 0 (1:28)

The expression bypasses compile-time type checking due to $env(...) being treated as an unknown type. Also the ternary operator deferring evaluation. Then at runtime UTC() is called with an argument - even though it takes none. When the OpCall handler accesses fnType.In(0) without checking its length, an index out of bounds panic happens, although recovered by the VM.

Changes

Added argument count validation in VM before attempting to call functions. Including a regression test.

Further comments

Functions that return no values are already caught by the checker at compile time, so the out[0] access after fn.Call() remains safe.

Regression from #889.

Nice edge case catched by the fuzzer.

Prevent index out of bounds panic when calling a function with more
arguments than it accepts. The VM now validates argument count before
attempting to access parameter types. Includes a regression test.

This issue was discovered by clusterfuzz with the expression:
$env(''matches'  '? :now().UTC(g).d)//

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
@thevilledev thevilledev marked this pull request as ready for review January 14, 2026 21: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.

1 participant