Explorar o código

add validation for array type in load_init_expr(GC only) (#4370)

Liu Jia hai 8 meses
pai
achega
7bbdbf5212
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      core/iwasm/aot/aot_loader.c

+ 7 - 0
core/iwasm/aot/aot_loader.c

@@ -1309,6 +1309,13 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
             read_uint32(buf, buf_end, type_idx);
             read_uint32(buf, buf_end, type_idx);
             read_uint32(buf, buf_end, length);
             read_uint32(buf, buf_end, length);
 
 
+            if (type_idx >= module->type_count
+                || !wasm_type_is_array_type(module->types[type_idx])) {
+                set_error_buf(error_buf, error_buf_size,
+                              "invalid or non-array type index.");
+                goto fail;
+            }
+
             if (init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT) {
             if (init_expr_type == INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT) {
                 expr->u.array_new_default.type_index = type_idx;
                 expr->u.array_new_default.type_index = type_idx;
                 expr->u.array_new_default.length = length;
                 expr->u.array_new_default.length = length;