Skip to content

Add validation for recursive type count in loader #4522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ check_array_type(const WASMModule *module, uint32 type_index, char *error_buf,
error_buf_size)) {
return false;
}
if (module->types[type_index] == NULL
|| module->types[type_index]->type_flag != WASM_TYPE_ARRAY) {
if (module->types[type_index]->type_flag != WASM_TYPE_ARRAY) {
set_error_buf(error_buf, error_buf_size, "unknown array type");
return false;
}
Expand All @@ -424,8 +423,7 @@ check_function_type(const WASMModule *module, uint32 type_index,
}

#if WASM_ENABLE_GC != 0
if (module->types[type_index] == NULL
|| module->types[type_index]->type_flag != WASM_TYPE_FUNC) {
if (module->types[type_index]->type_flag != WASM_TYPE_FUNC) {
set_error_buf(error_buf, error_buf_size, "unknown function type");
return false;
}
Expand Down Expand Up @@ -1257,9 +1255,8 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
error_buf_size)) {
goto fail;
}
if (module->types[type_idx] == NULL
|| module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
if (module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
set_error_buf(error_buf, error_buf_size,
"unknown struct type");
goto fail;
Expand Down Expand Up @@ -2499,6 +2496,13 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
#endif /* end of WASM_ENABLE_GC == 0 */
}

for (i = 0; i < module->type_count; i++) {
if (module->types[i] == NULL) {
set_error_buf_v(error_buf, error_buf_size, "unknown type %d", i);
return false;
}
}

if (p != p_end) {
set_error_buf(error_buf, error_buf_size, "section size mismatch");
return false;
Expand Down Expand Up @@ -12685,9 +12689,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
error_buf, error_buf_size)) {
goto fail;
}
if (module->types[type_idx1] == NULL
|| module->types[type_idx1]->type_flag
!= WASM_TYPE_FUNC) {
if (module->types[type_idx1]->type_flag != WASM_TYPE_FUNC) {
set_error_buf(error_buf, error_buf_size,
"unknown function type");
goto fail;
Expand All @@ -12704,9 +12706,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
error_buf, error_buf_size)) {
goto fail;
}
if (module->types[type_idx] == NULL
|| module->types[type_idx]->type_flag
!= WASM_TYPE_FUNC) {
if (module->types[type_idx]->type_flag != WASM_TYPE_FUNC) {
set_error_buf(error_buf, error_buf_size,
"unknown function type");
goto fail;
Expand Down Expand Up @@ -14542,9 +14542,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
error_buf_size)) {
goto fail;
}
if (module->types[type_idx] == NULL
|| module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
if (module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
set_error_buf(error_buf, error_buf_size,
"unknown struct type");
goto fail;
Expand Down Expand Up @@ -14630,9 +14629,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
error_buf_size)) {
goto fail;
}
if (module->types[type_idx] == NULL
|| module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
if (module->types[type_idx]->type_flag
!= WASM_TYPE_STRUCT) {
set_error_buf(error_buf, error_buf_size,
"unknown struct type");
goto fail;
Expand Down
Loading