Skip to content

Commit 1958808

Browse files
authored
Fix table index calculations in wasm_loader and wasm_mini_loader (#4004)
1 parent 099056b commit 1958808

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

core/iwasm/interpreter/wasm_loader.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ is_table_64bit(WASMModule *module, uint32 table_idx)
5858
return !!(module->import_tables[table_idx].u.table.table_type.flags
5959
& TABLE64_FLAG);
6060
else
61-
return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG);
61+
return !!(module->tables[table_idx - module->import_table_count]
62+
.table_type.flags
63+
& TABLE64_FLAG);
6264

6365
return false;
6466
}
@@ -4285,7 +4287,8 @@ check_table_elem_type(WASMModule *module, uint32 table_index,
42854287
module->import_tables[table_index].u.table.table_type.elem_type;
42864288
else
42874289
table_declared_elem_type =
4288-
(module->tables + table_index)->table_type.elem_type;
4290+
module->tables[table_index - module->import_table_count]
4291+
.table_type.elem_type;
42894292

42904293
if (table_declared_elem_type == type_from_elem_seg)
42914294
return true;
@@ -10854,12 +10857,12 @@ get_table_elem_type(const WASMModule *module, uint32 table_idx,
1085410857
else {
1085510858
if (p_elem_type)
1085610859
*p_elem_type =
10857-
module->tables[module->import_table_count + table_idx]
10860+
module->tables[table_idx - module->import_table_count]
1085810861
.table_type.elem_type;
1085910862
#if WASM_ENABLE_GC != 0
1086010863
if (p_ref_type)
1086110864
*((WASMRefType **)p_ref_type) =
10862-
module->tables[module->import_table_count + table_idx]
10865+
module->tables[table_idx - module->import_table_count]
1086310866
.table_type.elem_ref_type;
1086410867
#endif
1086510868
}

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ is_table_64bit(WASMModule *module, uint32 table_idx)
4848
return !!(module->import_tables[table_idx].u.table.table_type.flags
4949
& TABLE64_FLAG);
5050
else
51-
return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG);
51+
return !!(module->tables[table_idx - module->import_table_count]
52+
.table_type.flags
53+
& TABLE64_FLAG);
5254

5355
return false;
5456
}
@@ -2566,7 +2568,7 @@ get_table_elem_type(const WASMModule *module, uint32 table_idx,
25662568
module->import_tables[table_idx].u.table.table_type.elem_type;
25672569
else
25682570
*p_elem_type =
2569-
module->tables[module->import_table_count + table_idx]
2571+
module->tables[table_idx - module->import_table_count]
25702572
.table_type.elem_type;
25712573
}
25722574
return true;

0 commit comments

Comments
 (0)