@@ -6367,14 +6367,22 @@ check_wasi_abi_compatibility(const WASMModule *module,
6367
6367
/* clang-format on */
6368
6368
6369
6369
WASMExport *initialize = NULL, *memory = NULL, *start = NULL;
6370
+ uint32 import_function_count = module->import_function_count;
6371
+ WASMFuncType *func_type;
6370
6372
6371
6373
/* (func (export "_start") (...) */
6372
6374
start = wasm_loader_find_export(module, "", "_start", EXPORT_KIND_FUNC,
6373
6375
error_buf, error_buf_size);
6374
6376
if (start) {
6375
- WASMFuncType *func_type =
6376
- module->functions[start->index - module->import_function_count]
6377
- ->func_type;
6377
+ if (start->index < import_function_count) {
6378
+ set_error_buf(
6379
+ error_buf, error_buf_size,
6380
+ "the builtin _start function can not be an import function");
6381
+ return false;
6382
+ }
6383
+
6384
+ func_type =
6385
+ module->functions[start->index - import_function_count]->func_type;
6378
6386
if (func_type->param_count || func_type->result_count) {
6379
6387
set_error_buf(error_buf, error_buf_size,
6380
6388
"the signature of builtin _start function is wrong");
@@ -6386,11 +6394,17 @@ check_wasi_abi_compatibility(const WASMModule *module,
6386
6394
initialize =
6387
6395
wasm_loader_find_export(module, "", "_initialize", EXPORT_KIND_FUNC,
6388
6396
error_buf, error_buf_size);
6397
+
6389
6398
if (initialize) {
6390
- WASMFuncType *func_type =
6391
- module
6392
- ->functions[initialize->index
6393
- - module->import_function_count]
6399
+ if (initialize->index < import_function_count) {
6400
+ set_error_buf(error_buf, error_buf_size,
6401
+ "the builtin _initialize function can not be an "
6402
+ "import function");
6403
+ return false;
6404
+ }
6405
+
6406
+ func_type =
6407
+ module->functions[initialize->index - import_function_count]
6394
6408
->func_type;
6395
6409
if (func_type->param_count || func_type->result_count) {
6396
6410
set_error_buf(
@@ -9899,7 +9913,8 @@ wasm_loader_check_br(WASMLoaderContext *loader_ctx, uint32 depth,
9899
9913
bool is_type_multi_byte;
9900
9914
#endif
9901
9915
9902
- if (loader_ctx->csp_num < depth + 1) {
9916
+ bh_assert(loader_ctx->csp_num > 0);
9917
+ if (loader_ctx->csp_num - 1 < depth) {
9903
9918
set_error_buf(error_buf, error_buf_size,
9904
9919
"unknown label, "
9905
9920
"unexpected end of section or function");
0 commit comments