Fix potential integer overflow issues (#4429)

It is reported as "Multiplication result converted to larger type".
And "Multiplication result may overflow 'Type A' before it is
converted to 'Type B'." Type A is a larger type than Type B.

Since the conversion applies after the multiplication, arithmetic
overflow may still occur.

> The rule flags every multiplication of two non-constant integer expressions
> that is (explicitly or implicitly) converted to a larger integer type. The
> conversion is an indication that the expression would produce a result that
> would be too large to fit in the smaller integer type.
This commit is contained in:
liang.he
2025-07-01 13:39:30 +08:00
committed by GitHub
parent 8949797c84
commit c7148a6823
5 changed files with 8 additions and 6 deletions

View File

@ -302,8 +302,8 @@ get_init_expr_size(const AOTCompContext *comp_ctx, const AOTCompData *comp_data,
/* array_elem_type + type_index + len + elems */
size += sizeof(uint32) * 3
+ wasm_value_type_size_internal(array_type->elem_type,
comp_ctx->pointer_size)
+ (uint64)wasm_value_type_size_internal(
array_type->elem_type, comp_ctx->pointer_size)
* value_count;
break;
}

View File

@ -347,7 +347,8 @@ call_aot_invoke_c_api_native(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* Get &c_api_func_imports[func_idx], note size of CApiFuncImport
is pointer_size * 3 */
offset = I32_CONST((comp_ctx->pointer_size * 3) * import_func_idx);
offset = I32_CONST((unsigned long long)comp_ctx->pointer_size * 3
* import_func_idx);
CHECK_LLVM_CONST(offset);
c_api_func_import =
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, c_api_func_imports,