From e2afcbf648c6174ed2cd83a00e946e86f8849d01 Mon Sep 17 00:00:00 2001 From: stevenfontanella Date: Tue, 17 Mar 2026 21:11:36 +0000 Subject: [PATCH 1/2] Add validations for function imports --- scripts/test/shared.py | 4 +--- src/wasm-interpreter.h | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 1eb24b7ff1f..57c2d107eef 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -423,7 +423,7 @@ def get_tests(test_dir, extensions=[], recursive=False): 'if.wast', # Requires more precise unreachable validation 'imports.wast', # Requires fixing handling of mutation to imported globals 'proposals/threads/imports.wast', # Missing memory type validation on instantiation - 'linking.wast', # Missing function type validation on instantiation + 'linking.wast', # Missing global type validation on instantiation 'proposals/threads/memory.wast', # Missing memory type validation on instantiation 'annotations.wast', # String annotations IDs should be allowed 'instance.wast', # Requires support for table default elements @@ -445,8 +445,6 @@ def get_tests(test_dir, extensions=[], recursive=False): 'ref_cast.wast', # Requires host references to not be externalized i31refs 'ref_test.wast', # Requires host references to not be externalized i31refs 'struct.wast', # Fails to roundtrip unnamed types e.g. `(ref 0)` - 'type-rec.wast', # Missing function type validation on instantiation - 'type-subtyping.wast', # ShellExternalInterface::callTable does not handle subtyping 'memory64.wast', # Requires validations on the max memory size 'imports3.wast', # Requires better checking of exports from the special "spectest" module 'relaxed_dot_product.wast', # i16x8.relaxed_dot_i8x16_i7x16_s instruction not supported diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 369745d0b67..9c4107c2aec 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3450,9 +3450,7 @@ class ModuleRunnerBase : public ExpressionRunner { if (!MemoryUtils::isSubType(exportedMemory, **memory)) { trap("Imported memory isn't compatible."); } - } - - if (auto** tableDecl = std::get_if(&import)) { + } else if (auto** tableDecl = std::get_if(&import)) { auto* importedTable = importResolver->getTableOrNull( importable->importNames(), **tableDecl); if (!importedTable) { @@ -3468,7 +3466,19 @@ class ModuleRunnerBase : public ExpressionRunner { << " isn't compatible with import declaration: " << **tableDecl) .str()); } + } else if (auto** function = std::get_if(&import)) { + auto exportedFunc = getFunction((*function)->name); + if (!Type::isSubType(exportedFunc.type, (*function)->type)) { + trap((std::stringstream() + << "Imported function with type " + << exportedFunc.type.getHeapType().getSignature().toString() + << " isn't compatible with import declaration: " + << (*function)->type.getHeapType().getSignature().toString()) + .str()); + } } + + // TODO: remaining cases e.g. globals and tags. }); } From 4619bfac4a07eaab8474018ae3391ed2cb17e13d Mon Sep 17 00:00:00 2001 From: stevenfontanella Date: Wed, 18 Mar 2026 17:58:10 +0000 Subject: [PATCH 2/2] Update error message --- src/wasm-interpreter.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 9c4107c2aec..40a9d9e54cb 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3470,9 +3470,11 @@ class ModuleRunnerBase : public ExpressionRunner { auto exportedFunc = getFunction((*function)->name); if (!Type::isSubType(exportedFunc.type, (*function)->type)) { trap((std::stringstream() - << "Imported function with type " + << "Imported function " << importable->importNames() + << " with type " << exportedFunc.type.getHeapType().getSignature().toString() - << " isn't compatible with import declaration: " + << " isn't compatible with import declaration with type " + "(modulo rec groups): " << (*function)->type.getHeapType().getSignature().toString()) .str()); }