Fix tableidx overflow on call_indirect #303
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On some programs, the vm can run into an error like this
Unsigned LEB at byte 0x12800b011 overflow
. This overflow occurs when reading table indexes on thecall_indirect
function. It occurs because the table index in WARDuino can at most consist of 7 or 1 bits (the maximum amount of bit differs in two parts of the vm). In the wasm specification however, the table index is specified to be a u32. You would expect this error to only occur on modules using multiple tables but as it turns out this also happens on rust binaries that use just a single table. The reason for this is that the rust compiler can sometimes use a 5 byte table index0x80 0x80 0x80 0x80 0x00
to encode table index 0 as described in this blog post. Any binary using such an index will fail to execute, this PR fixes that.This PR also adds an error message for stack overflows during
setup_call
when in debug/trace/warn/info mode. This way users attempting to run bigger programs will more quickly realize that they just need to increase the stack size (or run their program in release mode) and it's not an issue with the vm implementation.