@@ -525,6 +525,25 @@ pub fn call_function<'a>(
525
525
. get_memory ( & mut store, "memory" )
526
526
. ok_or ( Error :: Wasm ( WasmError :: MemoryNotFound ) ) ?;
527
527
528
+ // Validate argument count
529
+ let expected_args = func_types. get_arg_types ( ) ;
530
+ if args. len ( ) != expected_args. len ( ) {
531
+ return Err ( Error :: Unchecked ( CheckErrors :: IncorrectArgumentCount (
532
+ expected_args. len ( ) ,
533
+ args. len ( ) ,
534
+ ) ) ) ;
535
+ }
536
+
537
+ // Validate argument types
538
+ for ( arg, expected_type) in args. iter ( ) . zip ( expected_args. iter ( ) ) {
539
+ if !expected_type. admits ( & epoch, arg) ? {
540
+ return Err ( Error :: Unchecked ( CheckErrors :: TypeError (
541
+ expected_type. clone ( ) ,
542
+ TypeSignature :: type_of ( arg) ?,
543
+ ) ) ) ;
544
+ }
545
+ }
546
+
528
547
// Determine how much space is needed for arguments
529
548
let mut arg_size = 0 ;
530
549
for arg in func_types. get_arg_types ( ) {
@@ -534,7 +553,7 @@ pub fn call_function<'a>(
534
553
535
554
// Ensure that the memory has enough space for the arguments
536
555
let mut total_required_bytes = 0 ;
537
- for ( arg, ty) in args. iter ( ) . zip ( func_types . get_arg_types ( ) ) {
556
+ for ( arg, ty) in args. iter ( ) . zip ( expected_args ) {
538
557
total_required_bytes += get_required_bytes ( ty, arg) ?;
539
558
}
540
559
ensure_memory (
@@ -545,7 +564,7 @@ pub fn call_function<'a>(
545
564
546
565
// Convert the args into wasmtime values
547
566
let mut wasm_args = vec ! [ ] ;
548
- for ( arg, ty) in args. iter ( ) . zip ( func_types . get_arg_types ( ) ) {
567
+ for ( arg, ty) in args. iter ( ) . zip ( expected_args ) {
549
568
let ( arg_vec, new_offset, new_in_mem_offset) =
550
569
pass_argument_to_wasm ( memory, & mut store, ty, arg, offset, in_mem_offset) ?;
551
570
wasm_args. extend ( arg_vec) ;
0 commit comments