Skip to content

Commit 0f642f3

Browse files
authored
Fuzzer: Don't legalize if there is an imported module to fuzz with (#8027)
If we import another module in a fuzz testcase, legalization could break the contract between them.
1 parent a592b76 commit 0f642f3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/tools/fuzzing/fuzzing.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,11 @@ void TranslateToFuzzReader::pickPasses(OptimizationOptions& options) {
323323

324324
// Prune things that error in JS if we call them (like SIMD), some of the
325325
// time. This alters the wasm/JS boundary quite a lot, so testing both forms
326-
// is useful.
327-
if (oneIn(2)) {
326+
// is useful. Note that we do not do this if there is an imported module,
327+
// because in that case legalization could alter the contract between the two
328+
// (that is, if the first module has an i64 param, we must call it like that,
329+
// and not as two i32s which we'd get after legalization).
330+
if (!importedModule && oneIn(2)) {
328331
options.passes.push_back("legalize-and-prune-js-interface");
329332
}
330333

src/tools/wasm-opt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ For more on how to optimize effectively, see
346346
if (translateToFuzz) {
347347
TranslateToFuzzReader reader(
348348
wasm, options.extra["infile"], options.passOptions.closedWorld);
349-
if (fuzzPasses) {
350-
reader.pickPasses(options);
351-
}
352349
reader.setAllowMemory(fuzzMemory);
353350
reader.setAllowOOB(fuzzOOB);
354351
reader.setPreserveImportsAndExports(fuzzPreserveImportsAndExports);
355352
if (!fuzzImport.empty()) {
356353
reader.setImportedModule(fuzzImport);
357354
}
355+
if (fuzzPasses) {
356+
reader.pickPasses(options);
357+
}
358358
reader.build();
359359
if (options.passOptions.validate) {
360360
if (!WasmValidator().validate(wasm, options.passOptions)) {

0 commit comments

Comments
 (0)