@@ -508,6 +508,53 @@ fn linker_func_wrap() -> Result<()> {
508508 } )
509509}
510510
511+ #[ test]
512+ #[ cfg( arc_try_new) ]
513+ fn module_deserialize ( ) -> Result < ( ) > {
514+ let module_bytes = {
515+ let mut config = Config :: new ( ) ;
516+ config. concurrency_support ( false ) ;
517+ let engine = Engine :: new ( & config) ?;
518+ let module = Module :: new (
519+ & engine,
520+ r#"
521+ (module
522+ (import "module" "func" (func (param i32) (result i32)))
523+
524+ (memory (export "memory") 1)
525+ (data (i32.const 0) "a")
526+
527+ (table (export "table") 1 funcref)
528+ (elem (i32.const 0) func 1)
529+
530+ (func (export "func") (param i32) (result i32)
531+ (call 0 (local.get 0))
532+ )
533+ )
534+ "# ,
535+ ) ?;
536+ module. serialize ( ) ?
537+ } ;
538+
539+ let mut config = Config :: new ( ) ;
540+ config. enable_compiler ( false ) ;
541+ config. concurrency_support ( false ) ;
542+ let engine = Engine :: new ( & config) ?;
543+
544+ OomTest :: new ( )
545+ // NB: We use `postcard` to deserialize module metadata, and it will
546+ // return a `postcard::Error::SerdeDeCustom` when we generate an
547+ // `OutOfMemory` error during deserialization. That is then converted
548+ // into a `wasmtime::Error`, and in the process we will attempt to box
549+ // that into an `Error` trait object. There is no good way to avoid all
550+ // this, so just allow allocation attempts after OOM here.
551+ . allow_alloc_after_oom ( true )
552+ . test ( || unsafe {
553+ let _ = Module :: deserialize ( & engine, & module_bytes) ?;
554+ Ok ( ( ) )
555+ } )
556+ }
557+
511558#[ test]
512559#[ cfg( arc_try_new) ]
513560fn store_try_new ( ) -> Result < ( ) > {
0 commit comments