@@ -104,7 +104,9 @@ wasm_byte_vec_copy(wasm_byte_vec_t *out, const wasm_byte_vec_t *src)
104
104
goto failed ;
105
105
}
106
106
107
- len = src -> size * src -> size_of_elem ;
107
+ /* integer overflow has been checked in generic_vec_init_data,
108
+ no need to check again */
109
+ len = (uint32 )(src -> size * src -> size_of_elem );
108
110
bh_memcpy_s (out -> data , len , src -> data , len );
109
111
out -> num_elems = src -> num_elems ;
110
112
return ;
@@ -117,7 +119,7 @@ wasm_byte_vec_copy(wasm_byte_vec_t *out, const wasm_byte_vec_t *src)
117
119
void
118
120
wasm_byte_vec_new (wasm_byte_vec_t * out , size_t size , const wasm_byte_t * data )
119
121
{
120
- size_t size_in_bytes = 0 ;
122
+ uint32 size_in_bytes = 0 ;
121
123
122
124
bh_assert (out && data );
123
125
@@ -126,7 +128,9 @@ wasm_byte_vec_new(wasm_byte_vec_t *out, size_t size, const wasm_byte_t *data)
126
128
goto failed ;
127
129
}
128
130
129
- size_in_bytes = size * sizeof (wasm_byte_t );
131
+ /* integer overflow has been checked in generic_vec_init_data,
132
+ no need to check again */
133
+ size_in_bytes = (uint32 )(size * sizeof (wasm_byte_t ));
130
134
bh_memcpy_s (out -> data , size_in_bytes , data , size_in_bytes );
131
135
out -> num_elems = size ;
132
136
return ;
@@ -435,14 +439,16 @@ wasm_valtype_vec_new(wasm_valtype_vec_t *out,
435
439
size_t size ,
436
440
wasm_valtype_t * const data [])
437
441
{
438
- size_t size_in_bytes = 0 ;
442
+ uint32 size_in_bytes = 0 ;
439
443
bh_assert (out && data );
440
444
generic_vec_init_data ((Vector * )out , size , sizeof (wasm_valtype_t * ));
441
445
if (!out -> data ) {
442
446
goto failed ;
443
447
}
444
448
445
- size_in_bytes = size * sizeof (wasm_valtype_t * );
449
+ /* integer overflow has been checked in generic_vec_init_data,
450
+ no need to check again */
451
+ size_in_bytes = (uint32 )(size * sizeof (wasm_valtype_t * ));
446
452
bh_memcpy_s (out -> data , size_in_bytes , data , size_in_bytes );
447
453
out -> num_elems = size ;
448
454
return ;
@@ -924,17 +930,21 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
924
930
check_engine_and_store (singleton_engine , store );
925
931
bh_assert (binary && binary -> data && binary -> size );
926
932
927
- pkg_type = get_package_type ((uint8 * )binary -> data , binary -> size );
933
+ if (binary -> size > UINT32_MAX ) {
934
+ LOG_ERROR ("%s failed" , __FUNCTION__ );
935
+ return NULL ;
936
+ }
937
+
938
+ pkg_type = get_package_type ((uint8 * )binary -> data , (uint32 )binary -> size );
928
939
if (Package_Type_Unknown == pkg_type
929
940
|| (Wasm_Module_Bytecode == pkg_type
930
941
&& INTERP_MODE != current_runtime_mode ())
931
942
|| (Wasm_Module_AoT == pkg_type
932
943
&& INTERP_MODE == current_runtime_mode ())) {
933
- LOG_WARNING (
934
- "current runtime mode %d doesn\'t support the package type "
935
- "%d" ,
944
+ LOG_ERROR (
945
+ "current runtime mode %d doesn\'t support the package type %d" ,
936
946
current_runtime_mode (), pkg_type );
937
- goto failed ;
947
+ return NULL ;
938
948
}
939
949
940
950
module_ex = malloc_internal (sizeof (wasm_module_ex_t ));
@@ -954,10 +964,12 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
954
964
955
965
module_ex -> module_comm_rt =
956
966
wasm_runtime_load ((uint8 * )module_ex -> binary -> data ,
957
- module_ex -> binary -> size , error , (uint32 )sizeof (error ));
967
+ (uint32 )module_ex -> binary -> size ,
968
+ error , (uint32 )sizeof (error ));
958
969
if (!(module_ex -> module_comm_rt )) {
959
970
LOG_ERROR (error );
960
- goto failed ;
971
+ wasm_module_delete_internal (module_ext_to_module (module_ex ));
972
+ return NULL ;
961
973
}
962
974
963
975
/* add it to a watching list in store */
@@ -968,7 +980,7 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
968
980
return module_ext_to_module (module_ex );
969
981
970
982
failed :
971
- LOG_DEBUG ("%s failed" , __FUNCTION__ );
983
+ LOG_ERROR ("%s failed" , __FUNCTION__ );
972
984
wasm_module_delete_internal (module_ext_to_module (module_ex ));
973
985
return NULL ;
974
986
}
@@ -2687,7 +2699,7 @@ wasm_extern_delete(wasm_extern_t *external)
2687
2699
wasm_externkind_t
2688
2700
wasm_extern_kind (const wasm_extern_t * extrenal )
2689
2701
{
2690
- return extrenal -> kind ;
2702
+ return ( wasm_externkind_t ) extrenal -> kind ;
2691
2703
}
2692
2704
2693
2705
wasm_func_t *
0 commit comments