|
|
@@ -21,6 +21,7 @@
|
|
|
#include "wasm_runtime.h"
|
|
|
#include "wasm_log.h"
|
|
|
#include "wasm_memory.h"
|
|
|
+#include "wasm_dlfcn.h"
|
|
|
|
|
|
/* Read a value of given type from the address pointed to by the given
|
|
|
pointer and increase the pointer to the position just after the
|
|
|
@@ -140,7 +141,8 @@ const_str_set_insert(const uint8 *str, int32 len, WASMModule *module,
|
|
|
|
|
|
if (!c_str) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM module load failed: alloc memory failed.");
|
|
|
+ "WASM module load failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
@@ -233,7 +235,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->type_count = type_count;
|
|
|
if (!(module->types = wasm_malloc(sizeof(WASMType*) * type_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load type section failed: alloc memory failed.");
|
|
|
+ "Load type section failed: allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -255,13 +257,20 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
CHECK_BUF(p, p_end, param_count);
|
|
|
p += param_count;
|
|
|
read_leb_uint32(p, p_end, result_count);
|
|
|
- wasm_assert(result_count <= 1);
|
|
|
+ if (result_count > 1) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "Load type section failed: invalid result count.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
CHECK_BUF(p, p_end, result_count);
|
|
|
p = p_org;
|
|
|
|
|
|
if (!(type = module->types[i] = wasm_malloc(offsetof(WASMType, types) +
|
|
|
- sizeof(uint8) * (param_count + result_count))))
|
|
|
+ sizeof(uint8) * (param_count + result_count)))) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "Load type section failed: allocate memory failed.");
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
/* Resolve param types and result types */
|
|
|
type->param_count = param_count;
|
|
|
@@ -412,7 +421,7 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->import_count = import_count;
|
|
|
if (!(module->imports = wasm_malloc(sizeof(WASMImport) * import_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load import section failed: alloc memory failed.");
|
|
|
+ "Load import section failed: allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -634,7 +643,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
module->function_count = func_count;
|
|
|
if (!(module->functions = wasm_malloc(sizeof(WASMFunction*) * func_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load function section failed: alloc memory failed.");
|
|
|
+ "Load function section failed: allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -651,7 +660,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
}
|
|
|
|
|
|
read_leb_uint32(p_code, buf_code_end, code_size);
|
|
|
- if (code_size == 0) {
|
|
|
+ if (code_size == 0
|
|
|
+ || p_code + code_size > buf_code_end) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"Load function section failed: "
|
|
|
"invalid function code size.");
|
|
|
@@ -677,7 +687,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
|
|
|
if (!(func = module->functions[i] = wasm_malloc(total_size))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load function section failed: alloc memory failed.");
|
|
|
+ "Load function section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -695,7 +706,20 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
local_type_index = 0;
|
|
|
for (j = 0; j < local_set_count; j++) {
|
|
|
read_leb_uint32(p_code, buf_code_end, sub_local_count);
|
|
|
+ if (local_type_index + sub_local_count <= local_type_index
|
|
|
+ || local_type_index + sub_local_count > local_count) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "Load function section failed: "
|
|
|
+ "invalid local count.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
read_leb_uint8(p_code, buf_code_end, type);
|
|
|
+ if (type < VALUE_TYPE_F64 || type > VALUE_TYPE_I32) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "Load function section failed: "
|
|
|
+ "invalid local type.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
for (k = 0; k < sub_local_count; k++) {
|
|
|
func->local_types[local_type_index++] = type;
|
|
|
}
|
|
|
@@ -706,8 +730,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
|
|
|
if (p != p_end) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load function section failed: "
|
|
|
- "invalid section size.");
|
|
|
+ "Load function section failed: "
|
|
|
+ "invalid section size.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -734,7 +758,8 @@ load_table_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->table_count = table_count;
|
|
|
if (!(module->tables = wasm_malloc(sizeof(WASMTable) * table_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load table section failed: alloc memory failed.");
|
|
|
+ "Load table section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -776,7 +801,8 @@ load_memory_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->memory_count = memory_count;
|
|
|
if (!(module->memories = wasm_malloc(sizeof(WASMMemory) * memory_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load memory section failed: alloc memory failed.");
|
|
|
+ "Load memory section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -813,7 +839,8 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->global_count = global_count;
|
|
|
if (!(module->globals = wasm_malloc(sizeof(WASMGlobal) * global_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load global section failed: alloc memory failed.");
|
|
|
+ "Load global section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -858,7 +885,8 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->export_count = export_count;
|
|
|
if (!(module->exports = wasm_malloc(sizeof(WASMExport) * export_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load export section failed: alloc memory failed.");
|
|
|
+ "Load export section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -951,7 +979,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
|
|
|
(sizeof(WASMTableSeg) * table_segment_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"Load table segment section failed: "
|
|
|
- "alloc memory failed.");
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -973,7 +1001,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *m
|
|
|
wasm_malloc(sizeof(uint32) * function_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"Load table segment section failed: "
|
|
|
- "alloc memory failed.");
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
for (j = 0; j < function_count; j++) {
|
|
|
@@ -1011,8 +1039,8 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
if (!(module->data_segments =
|
|
|
wasm_malloc(sizeof(WASMDataSeg*) * data_seg_count))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "Load data segment section failed, "
|
|
|
- "alloc memory failed.");
|
|
|
+ "Load data segment section failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -1030,7 +1058,7 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
wasm_malloc(sizeof(WASMDataSeg)))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"Load data segment section failed: "
|
|
|
- "alloc memory failed.");
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -1116,12 +1144,6 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
section = section->next;
|
|
|
}
|
|
|
|
|
|
- if (!buf_code) {
|
|
|
- set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM module load failed: find code section failed.");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
section = sections;
|
|
|
while (section) {
|
|
|
buf = section->section_body;
|
|
|
@@ -1139,8 +1161,13 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
return false;
|
|
|
break;
|
|
|
case SECTION_TYPE_FUNC:
|
|
|
+ if (!buf_code) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "WASM module load failed: find code section failed.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (!load_function_section(buf, buf_end, buf_code, buf_code_end,
|
|
|
- module, error_buf, error_buf_size))
|
|
|
+ module, error_buf, error_buf_size))
|
|
|
return false;
|
|
|
break;
|
|
|
case SECTION_TYPE_TABLE:
|
|
|
@@ -1228,7 +1255,8 @@ create_module(char *error_buf, uint32 error_buf_size)
|
|
|
|
|
|
if (!module) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM module load failed: alloc memory failed.");
|
|
|
+ "WASM module load failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
@@ -1308,7 +1336,8 @@ create_sections(const uint8 *buf, uint32 size,
|
|
|
|
|
|
if (!(section = wasm_malloc(sizeof(WASMSection)))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM module load failed: alloc memory failed.");
|
|
|
+ "WASM module load failed: "
|
|
|
+ "allocate memory failed.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -1335,6 +1364,25 @@ create_sections(const uint8 *buf, uint32 size,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+exchange32(uint8* p_data)
|
|
|
+{
|
|
|
+ uint8 value = *p_data;
|
|
|
+ *p_data = *(p_data + 3);
|
|
|
+ *(p_data + 3) = value;
|
|
|
+
|
|
|
+ value = *(p_data + 1);
|
|
|
+ *(p_data + 1) = *(p_data + 2);
|
|
|
+ *(p_data + 2) = value;
|
|
|
+}
|
|
|
+
|
|
|
+static union {
|
|
|
+ int a;
|
|
|
+ char b;
|
|
|
+} __ue = { .a = 1 };
|
|
|
+
|
|
|
+#define is_little_endian() (__ue.b == 1)
|
|
|
+
|
|
|
static bool
|
|
|
load(const uint8 *buf, uint32 size, WASMModule *module,
|
|
|
char *error_buf, uint32 error_buf_size)
|
|
|
@@ -1345,13 +1393,21 @@ load(const uint8 *buf, uint32 size, WASMModule *module,
|
|
|
WASMSection *section_list = NULL;
|
|
|
|
|
|
CHECK_BUF(p, p_end, sizeof(uint32));
|
|
|
- if ((magic_number = read_uint32(p)) != WASM_MAGIC_NUMBER) {
|
|
|
+ magic_number = read_uint32(p);
|
|
|
+ if (!is_little_endian())
|
|
|
+ exchange32((uint8*)&magic_number);
|
|
|
+
|
|
|
+ if (magic_number != WASM_MAGIC_NUMBER) {
|
|
|
set_error_buf(error_buf, error_buf_size, "magic header not detected");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
CHECK_BUF(p, p_end, sizeof(uint32));
|
|
|
- if ((version = read_uint32(p)) != WASM_CURRENT_VERSION) {
|
|
|
+ version = read_uint32(p);
|
|
|
+ if (!is_little_endian())
|
|
|
+ exchange32((uint8*)&version);
|
|
|
+
|
|
|
+ if (version != WASM_CURRENT_VERSION) {
|
|
|
set_error_buf(error_buf, error_buf_size, "unknown binary version");
|
|
|
return false;
|
|
|
}
|
|
|
@@ -1373,7 +1429,7 @@ wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_bu
|
|
|
|
|
|
if (!module) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM module load failed: alloc memory failed.");
|
|
|
+ "WASM module load failed: allocate memory failed.");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
@@ -1827,9 +1883,11 @@ wasm_loader_find_block_addr(WASMModule *module,
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- LOG_ERROR("WASM loader find block addr failed: invalid opcode %02x.\n",
|
|
|
- opcode);
|
|
|
- break;
|
|
|
+ if (error_buf)
|
|
|
+ snprintf(error_buf, error_buf_size,
|
|
|
+ "WASM loader find block addr failed: "
|
|
|
+ "invalid opcode %02x.", opcode);
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1874,7 +1932,7 @@ memory_realloc(void *mem_old, uint32 size_old, uint32 size_new)
|
|
|
if (!mem_new) { \
|
|
|
set_error_buf(error_buf, error_buf_size, \
|
|
|
"WASM loader prepare bytecode failed: " \
|
|
|
- "alloc memory failed"); \
|
|
|
+ "allocate memory failed."); \
|
|
|
goto fail; \
|
|
|
} \
|
|
|
mem = mem_new; \
|
|
|
@@ -2173,6 +2231,24 @@ pop_type(uint8 type, uint8 **p_frame_ref, uint32 *p_stack_cell_num,
|
|
|
} \
|
|
|
} while (0)
|
|
|
|
|
|
+static bool
|
|
|
+check_memory(WASMModule *module,
|
|
|
+ char *error_buf, uint32 error_buf_size)
|
|
|
+{
|
|
|
+ if (module->memory_count == 0
|
|
|
+ && module->import_memory_count == 0) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "load or store in module without default memory");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+#define CHECK_MEMORY() do { \
|
|
|
+ if (!check_memory(module, error_buf, error_buf_size)) \
|
|
|
+ goto fail; \
|
|
|
+ } while (0)
|
|
|
+
|
|
|
static bool
|
|
|
wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
char *error_buf, uint32 error_buf_size)
|
|
|
@@ -2207,7 +2283,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
frame_ref_size = 32;
|
|
|
if (!(frame_ref_bottom = frame_ref = wasm_malloc(frame_ref_size))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM loader prepare bytecode failed: alloc memory failed");
|
|
|
+ "WASM loader prepare bytecode failed: "
|
|
|
+ "allocate memory failed");
|
|
|
goto fail;
|
|
|
}
|
|
|
memset(frame_ref_bottom, 0, frame_ref_size);
|
|
|
@@ -2216,7 +2293,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
frame_csp_size = sizeof(BranchBlock) * 8;
|
|
|
if (!(frame_csp_bottom = frame_csp = wasm_malloc(frame_csp_size))) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
- "WASM loader prepare bytecode failed: alloc memory failed");
|
|
|
+ "WASM loader prepare bytecode failed: "
|
|
|
+ "allocate memory failed");
|
|
|
goto fail;
|
|
|
}
|
|
|
|
|
|
@@ -2309,7 +2387,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
if (!block) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"WASM loader prepare bytecode failed: "
|
|
|
- "alloc memory failed");
|
|
|
+ "allocate memory failed.");
|
|
|
goto fail;
|
|
|
}
|
|
|
|
|
|
@@ -2322,7 +2400,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|
|
block)) {
|
|
|
set_error_buf(error_buf, error_buf_size,
|
|
|
"WASM loader prepare bytecode failed: "
|
|
|
- "alloc memory failed");
|
|
|
+ "allocate memory failed.");
|
|
|
wasm_free(block);
|
|
|
goto fail;
|
|
|
}
|
|
|
@@ -2454,12 +2532,20 @@ handle_op_br:
|
|
|
WASMType *func_type;
|
|
|
uint32 type_idx;
|
|
|
|
|
|
+ if (module->table_count == 0
|
|
|
+ && module->import_table_count == 0) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "call indirect without default table");
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
read_leb_uint32(p, p_end, type_idx);
|
|
|
read_leb_uint8(p, p_end, u8); /* 0x00 */
|
|
|
POP_I32();
|
|
|
|
|
|
if (type_idx >= module->type_count) {
|
|
|
- set_error_buf(error_buf, error_buf_size, "function index is overflow");
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "function index is overflow");
|
|
|
goto fail;
|
|
|
}
|
|
|
|
|
|
@@ -2590,6 +2676,7 @@ handle_op_br:
|
|
|
case WASM_OP_I32_LOAD8_U:
|
|
|
case WASM_OP_I32_LOAD16_S:
|
|
|
case WASM_OP_I32_LOAD16_U:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I32();
|
|
|
@@ -2603,6 +2690,7 @@ handle_op_br:
|
|
|
case WASM_OP_I64_LOAD16_U:
|
|
|
case WASM_OP_I64_LOAD32_S:
|
|
|
case WASM_OP_I64_LOAD32_U:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I32();
|
|
|
@@ -2610,6 +2698,7 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_F32_LOAD:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I32();
|
|
|
@@ -2617,6 +2706,7 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_F64_LOAD:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I32();
|
|
|
@@ -2626,6 +2716,7 @@ handle_op_br:
|
|
|
case WASM_OP_I32_STORE:
|
|
|
case WASM_OP_I32_STORE8:
|
|
|
case WASM_OP_I32_STORE16:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I32();
|
|
|
@@ -2636,6 +2727,7 @@ handle_op_br:
|
|
|
case WASM_OP_I64_STORE8:
|
|
|
case WASM_OP_I64_STORE16:
|
|
|
case WASM_OP_I64_STORE32:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_I64();
|
|
|
@@ -2643,6 +2735,7 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_F32_STORE:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_F32();
|
|
|
@@ -2650,6 +2743,7 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_F64_STORE:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* align */
|
|
|
read_leb_uint32(p, p_end, u32); /* offset */
|
|
|
POP_F64();
|
|
|
@@ -2657,11 +2751,13 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_MEMORY_SIZE:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* 0x00 */
|
|
|
PUSH_I32();
|
|
|
break;
|
|
|
|
|
|
case WASM_OP_MEMORY_GROW:
|
|
|
+ CHECK_MEMORY();
|
|
|
read_leb_uint32(p, p_end, u32); /* 0x00 */
|
|
|
POP_I32();
|
|
|
PUSH_I32();
|
|
|
@@ -2943,15 +3039,24 @@ handle_op_br:
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- LOG_ERROR("WASM loader find block addr failed: invalid opcode %02x.\n",
|
|
|
- opcode);
|
|
|
- break;
|
|
|
+ if (error_buf != NULL)
|
|
|
+ snprintf(error_buf, error_buf_size,
|
|
|
+ "WASM module load failed: "
|
|
|
+ "invalid opcode %02x.", opcode);
|
|
|
+ goto fail;
|
|
|
}
|
|
|
|
|
|
if (opcode != WASM_OP_I32_CONST)
|
|
|
is_i32_const = false;
|
|
|
}
|
|
|
|
|
|
+ if (csp_num > 0) {
|
|
|
+ set_error_buf(error_buf, error_buf_size,
|
|
|
+ "WASM module load failed: "
|
|
|
+ "function body must end with END opcode.");
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
func->max_stack_cell_num = max_stack_cell_num;
|
|
|
func->max_block_num = max_csp_num;
|
|
|
return_value = true;
|