From 1ee4767d974c65ce9a5554f2e3dab16d074e487c Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Wed, 3 Jan 2024 11:43:03 +0800 Subject: [PATCH] Fix ref.func function declared check in wasm loader (#2972) The forward-declare function reference in ref.func can be declared in table element segments, no matter whether the segment mode is passive, active or declarative. Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2944. --- core/iwasm/interpreter/wasm_loader.c | 7 ++++--- core/iwasm/interpreter/wasm_mini_loader.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index b770a771..4098d1af 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -8116,10 +8116,11 @@ re_scan: bool func_declared = false; uint32 j; - /* Check whether the function is declared in table segs */ + /* Check whether the function is declared in table segs, + note that it doesn't matter whether the table seg's mode + is passive, active or declarative. */ for (i = 0; i < module->table_seg_count; i++, table_seg++) { - if (table_seg->elem_type == VALUE_TYPE_FUNCREF - && wasm_elem_is_declarative(table_seg->mode)) { + if (table_seg->elem_type == VALUE_TYPE_FUNCREF) { for (j = 0; j < table_seg->function_count; j++) { if (table_seg->func_indexes[j] == func_idx) { func_declared = true; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 6a63f516..8262de82 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -6411,10 +6411,11 @@ re_scan: bool func_declared = false; uint32 j; - /* Check whether the function is declared in table segs */ + /* Check whether the function is declared in table segs, + note that it doesn't matter whether the table seg's mode + is passive, active or declarative. */ for (i = 0; i < module->table_seg_count; i++, table_seg++) { - if (table_seg->elem_type == VALUE_TYPE_FUNCREF - && wasm_elem_is_declarative(table_seg->mode)) { + if (table_seg->elem_type == VALUE_TYPE_FUNCREF) { for (j = 0; j < table_seg->function_count; j++) { if (table_seg->func_indexes[j] == func_idx) { func_declared = true;