bytecodealliance / bytecodealliance/endive

Wrong argument count when calling exported functions is not properly handled

Open
#99 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
296
Forks
21
Avg merge
2d 12h
Merged PRs (30d)
29

Description

## Version
- Endive 1.0.1
- OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS)

## Description
It looks like calling an exported function with an incorrect number of arguments is not properly handled:
- interpreter: silently shortens or expands arguments array here https://github.com/bytecodealliance/endive/blob/75057984f851fd2b13fb04db42f66ab5600585ae/runtime/src/main/java/run/endive/runtime/StackFrame.java#L59
- runtime compilation: causes `ArrayIndexOutOfBoundsException` without much details

Not sure what the specification requires, but ideally the behavior should be consistent and in case of an error throw a user-friendly exception.

Here is an example:
```java
byte[] bytes = Base64.getDecoder().decode("AGFzbQEAAAABBgFgAX8BfwMCAQAHCwEHZXhhbXBsZQAACgYBBAAgAAsACgRuYW1lAgMBAAA");
WasmModule module = Parser.parse(bytes);
Instance instance = Instance.builder(module)
.withMachineFactory(MachineFactoryCompiler::compile)
.build();
ExportFunction export = instance.export("example");
export.apply();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.