@@ -525,6 +525,25 @@ pub fn call_function<'a>(
525525 . get_memory ( & mut store, "memory" )
526526 . ok_or ( Error :: Wasm ( WasmError :: MemoryNotFound ) ) ?;
527527
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+
528547 // Determine how much space is needed for arguments
529548 let mut arg_size = 0 ;
530549 for arg in func_types. get_arg_types ( ) {
@@ -534,7 +553,7 @@ pub fn call_function<'a>(
534553
535554 // Ensure that the memory has enough space for the arguments
536555 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 ) {
538557 total_required_bytes += get_required_bytes ( ty, arg) ?;
539558 }
540559 ensure_memory (
@@ -545,7 +564,7 @@ pub fn call_function<'a>(
545564
546565 // Convert the args into wasmtime values
547566 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 ) {
549568 let ( arg_vec, new_offset, new_in_mem_offset) =
550569 pass_argument_to_wasm ( memory, & mut store, ty, arg, offset, in_mem_offset) ?;
551570 wasm_args. extend ( arg_vec) ;
0 commit comments