Skip to content

Commit 744f748

Browse files
authored
Fuzzer: Use types from imported module (#7990)
Also improve the rate-handling in other places. Pick a rate of 0-10, then random numbers 0-9 compared with `num < rate`, which allows a rate of 0 to mean "never" and 10 to mean "always".
1 parent 61924cd commit 744f748

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/tools/fuzzing/fuzzing.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,17 @@ void TranslateToFuzzReader::setupHeapTypes() {
450450
// initial content we began with.
451451
auto possibleHeapTypes = ModuleUtils::collectHeapTypes(wasm);
452452

453+
// Use heap types from an imported module, if present.
454+
if (importedModule) {
455+
auto importedHeapTypes = ModuleUtils::collectHeapTypes(*importedModule);
456+
auto rate = upTo(11);
457+
for (auto type : importedHeapTypes) {
458+
if (upTo(10) < rate) {
459+
possibleHeapTypes.push_back(type);
460+
}
461+
}
462+
}
463+
453464
// Filter away uninhabitable heap types, that is, heap types that we cannot
454465
// construct, like a type with a non-nullable reference to itself.
455466
interestingHeapTypes = HeapTypeGenerator::getInhabitable(possibleHeapTypes);
@@ -1213,9 +1224,9 @@ void TranslateToFuzzReader::useImportedFunctions() {
12131224
}
12141225

12151226
// Add some of the module's exported functions as imports, at a random rate.
1216-
auto rate = upTo(100);
1227+
auto rate = upTo(11);
12171228
for (auto& exp : importedModule->exports) {
1218-
if (exp->kind != ExternalKind::Function || upTo(100) > rate) {
1229+
if (exp->kind != ExternalKind::Function || upTo(10) >= rate) {
12191230
continue;
12201231
}
12211232

@@ -1243,9 +1254,9 @@ void TranslateToFuzzReader::useImportedGlobals() {
12431254
}
12441255

12451256
// Add some of the module's exported globals as imports, at a random rate.
1246-
auto rate = upTo(100);
1257+
auto rate = upTo(11);
12471258
for (auto& exp : importedModule->exports) {
1248-
if (exp->kind != ExternalKind::Global || upTo(100) > rate) {
1259+
if (exp->kind != ExternalKind::Global || upTo(10) >= rate) {
12491260
continue;
12501261
}
12511262

0 commit comments

Comments
 (0)