diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index dca25fff59b..8702d7f2dca 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -450,6 +450,17 @@ void TranslateToFuzzReader::setupHeapTypes() { // initial content we began with. auto possibleHeapTypes = ModuleUtils::collectHeapTypes(wasm); + // Use heap types from an imported module, if present. + if (importedModule) { + auto importedHeapTypes = ModuleUtils::collectHeapTypes(*importedModule); + auto rate = upTo(11); + for (auto type : importedHeapTypes) { + if (upTo(10) < rate) { + possibleHeapTypes.push_back(type); + } + } + } + // Filter away uninhabitable heap types, that is, heap types that we cannot // construct, like a type with a non-nullable reference to itself. interestingHeapTypes = HeapTypeGenerator::getInhabitable(possibleHeapTypes); @@ -1213,9 +1224,9 @@ void TranslateToFuzzReader::useImportedFunctions() { } // Add some of the module's exported functions as imports, at a random rate. - auto rate = upTo(100); + auto rate = upTo(11); for (auto& exp : importedModule->exports) { - if (exp->kind != ExternalKind::Function || upTo(100) > rate) { + if (exp->kind != ExternalKind::Function || upTo(10) >= rate) { continue; } @@ -1243,9 +1254,9 @@ void TranslateToFuzzReader::useImportedGlobals() { } // Add some of the module's exported globals as imports, at a random rate. - auto rate = upTo(100); + auto rate = upTo(11); for (auto& exp : importedModule->exports) { - if (exp->kind != ExternalKind::Global || upTo(100) > rate) { + if (exp->kind != ExternalKind::Global || upTo(10) >= rate) { continue; }