wasm loader: Reject v128 for interpreters (#3611)
discussed in: https://github.com/bytecodealliance/wasm-micro-runtime/pull/3592
This commit is contained in:
@ -85,6 +85,21 @@ is_valid_value_type(uint8 type)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_valid_value_type_for_interpreter(uint8 value_type)
|
||||||
|
{
|
||||||
|
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0)
|
||||||
|
/*
|
||||||
|
* Note: regardless of WASM_ENABLE_SIMD, our interpreters don't have
|
||||||
|
* SIMD implemented. It's safer to reject v128, especially for the
|
||||||
|
* fast interpreter.
|
||||||
|
*/
|
||||||
|
if (value_type == VALUE_TYPE_V128)
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
return is_valid_value_type(value_type);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_valid_func_type(const WASMFuncType *func_type)
|
is_valid_func_type(const WASMFuncType *func_type)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,6 +20,9 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
|
|||||||
bool
|
bool
|
||||||
is_valid_value_type(uint8 value_tpye);
|
is_valid_value_type(uint8 value_tpye);
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_valid_value_type_for_interpreter(uint8 value_tpye);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_valid_func_type(const WASMFuncType *func_type);
|
is_valid_func_type(const WASMFuncType *func_type);
|
||||||
|
|
||||||
@ -31,4 +34,4 @@ is_indices_overflow(uint32 import, uint32 other, char *error_buf,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* end of _WASM_LOADER_COMMON_H */
|
#endif /* end of _WASM_LOADER_COMMON_H */
|
||||||
|
|||||||
@ -334,8 +334,10 @@ is_packed_type(uint8 type)
|
|||||||
static bool
|
static bool
|
||||||
is_byte_a_type(uint8 type)
|
is_byte_a_type(uint8 type)
|
||||||
{
|
{
|
||||||
return (is_valid_value_type(type) || (type == VALUE_TYPE_VOID)) ? true
|
return (is_valid_value_type_for_interpreter(type)
|
||||||
: false;
|
|| (type == VALUE_TYPE_VOID))
|
||||||
|
? true
|
||||||
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_SIMD != 0
|
#if WASM_ENABLE_SIMD != 0
|
||||||
@ -1443,7 +1445,7 @@ resolve_value_type(const uint8 **p_buf, const uint8 *buf_end,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* type which can be represented by one byte */
|
/* type which can be represented by one byte */
|
||||||
if (!is_valid_value_type(type)
|
if (!is_valid_value_type_for_interpreter(type)
|
||||||
&& !(allow_packed_type && is_packed_type(type))) {
|
&& !(allow_packed_type && is_packed_type(type))) {
|
||||||
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
||||||
return false;
|
return false;
|
||||||
@ -1953,7 +1955,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|||||||
type->types[param_count + j] = read_uint8(p);
|
type->types[param_count + j] = read_uint8(p);
|
||||||
}
|
}
|
||||||
for (j = 0; j < param_count + result_count; j++) {
|
for (j = 0; j < param_count + result_count; j++) {
|
||||||
if (!is_valid_value_type(type->types[j])) {
|
if (!is_valid_value_type_for_interpreter(type->types[j])) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"unknown value type");
|
"unknown value type");
|
||||||
return false;
|
return false;
|
||||||
@ -3049,7 +3051,7 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end,
|
|||||||
CHECK_BUF(p, p_end, 2);
|
CHECK_BUF(p, p_end, 2);
|
||||||
/* global type */
|
/* global type */
|
||||||
declare_type = read_uint8(p);
|
declare_type = read_uint8(p);
|
||||||
if (!is_valid_value_type(declare_type)) {
|
if (!is_valid_value_type_for_interpreter(declare_type)) {
|
||||||
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3766,7 +3768,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|||||||
CHECK_BUF(p_code, buf_code_end, 1);
|
CHECK_BUF(p_code, buf_code_end, 1);
|
||||||
/* 0x7F/0x7E/0x7D/0x7C */
|
/* 0x7F/0x7E/0x7D/0x7C */
|
||||||
type = read_uint8(p_code);
|
type = read_uint8(p_code);
|
||||||
if (!is_valid_value_type(type)) {
|
if (!is_valid_value_type_for_interpreter(type)) {
|
||||||
if (type == VALUE_TYPE_V128)
|
if (type == VALUE_TYPE_V128)
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"v128 value type requires simd feature");
|
"v128 value type requires simd feature");
|
||||||
@ -4046,7 +4048,7 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|||||||
CHECK_BUF(p, p_end, 2);
|
CHECK_BUF(p, p_end, 2);
|
||||||
/* global type */
|
/* global type */
|
||||||
global->type.val_type = read_uint8(p);
|
global->type.val_type = read_uint8(p);
|
||||||
if (!is_valid_value_type(global->type.val_type)) {
|
if (!is_valid_value_type_for_interpreter(global->type.val_type)) {
|
||||||
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
set_error_buf(error_buf, error_buf_size, "type mismatch");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -12367,7 +12369,7 @@ re_scan:
|
|||||||
#if WASM_ENABLE_GC == 0
|
#if WASM_ENABLE_GC == 0
|
||||||
CHECK_BUF(p, p_end, 1);
|
CHECK_BUF(p, p_end, 1);
|
||||||
type = read_uint8(p);
|
type = read_uint8(p);
|
||||||
if (!is_valid_value_type(type)) {
|
if (!is_valid_value_type_for_interpreter(type)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"unknown value type");
|
"unknown value type");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
@ -91,7 +91,8 @@ is_64bit_type(uint8 type)
|
|||||||
static bool
|
static bool
|
||||||
is_byte_a_type(uint8 type)
|
is_byte_a_type(uint8 type)
|
||||||
{
|
{
|
||||||
return is_valid_value_type(type) || (type == VALUE_TYPE_VOID);
|
return is_valid_value_type_for_interpreter(type)
|
||||||
|
|| (type == VALUE_TYPE_VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -568,7 +569,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|||||||
type->types[param_count + j] = read_uint8(p);
|
type->types[param_count + j] = read_uint8(p);
|
||||||
}
|
}
|
||||||
for (j = 0; j < param_count + result_count; j++) {
|
for (j = 0; j < param_count + result_count; j++) {
|
||||||
bh_assert(is_valid_value_type(type->types[j]));
|
bh_assert(is_valid_value_type_for_interpreter(type->types[j]));
|
||||||
}
|
}
|
||||||
|
|
||||||
param_cell_num = wasm_get_cell_num(type->types, param_count);
|
param_cell_num = wasm_get_cell_num(type->types, param_count);
|
||||||
@ -1218,7 +1219,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|||||||
CHECK_BUF(p_code, buf_code_end, 1);
|
CHECK_BUF(p_code, buf_code_end, 1);
|
||||||
/* 0x7F/0x7E/0x7D/0x7C */
|
/* 0x7F/0x7E/0x7D/0x7C */
|
||||||
type = read_uint8(p_code);
|
type = read_uint8(p_code);
|
||||||
bh_assert(is_valid_value_type(type));
|
bh_assert(is_valid_value_type_for_interpreter(type));
|
||||||
for (k = 0; k < sub_local_count; k++) {
|
for (k = 0; k < sub_local_count; k++) {
|
||||||
func->local_types[local_type_index++] = type;
|
func->local_types[local_type_index++] = type;
|
||||||
}
|
}
|
||||||
@ -6828,7 +6829,7 @@ re_scan:
|
|||||||
|
|
||||||
CHECK_BUF(p, p_end, 1);
|
CHECK_BUF(p, p_end, 1);
|
||||||
ref_type = read_uint8(p);
|
ref_type = read_uint8(p);
|
||||||
if (!is_valid_value_type(ref_type)) {
|
if (!is_valid_value_type_for_interpreter(ref_type)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"unknown value type");
|
"unknown value type");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
Reference in New Issue
Block a user