Skip to content

Fix tableidx overflow on call_indirect #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Interpreter/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ bool i_instr_call(Module *m) {
bool i_instr_call_indirect(Module *m) {
uint32_t tidx = read_LEB_32(&m->pc_ptr); // TODO: use tidx?
(void)tidx;
read_LEB(&m->pc_ptr, 1); // reserved immediate
read_LEB_32(&m->pc_ptr); // reserved immediate
uint32_t val = m->stack[m->sp--].value.uint32;
if (m->options.mangle_table_index) {
// val is the table address + the index (not sized for the
Expand Down
6 changes: 6 additions & 0 deletions src/Interpreter/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ void Interpreter::setup_call(Module *m, uint32_t fidx) {
// Push function locals
for (uint32_t lidx = 0; lidx < func->local_count; lidx++) {
m->sp += 1;
#if DEBUG || TRACE || WARN || INFO
if (m->sp >= STACK_SIZE) {
FATAL("WebAssembly stack overflow m->sp = %d, STACK_SIZE = %d\n",
m->sp, STACK_SIZE);
}
#endif
m->stack[m->sp].value_type = func->local_value_type[lidx];
m->stack[m->sp].value = {0}; // Initialize whole union to 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/WARDuino/WARDuino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void skip_immediates(uint8_t **pos) {
case 0x11: // call_indirect
// encoding: 0x11 x 0x00
read_LEB_32(pos); // read x
read_LEB(pos, 7); // 0x00 byte
read_LEB_32(pos); // 0x00 byte
break;
// varint64
case 0x42: // i64.const
Expand Down