Skip to content

Commit f9d78d8

Browse files
authored
Fuzzing: Handle instantiation errors in ClusterFuzz (#7166)
If the module has an invalid segment offset, for example, it will error. We should not error in the fuzzer on such rare cases. Also add logging of the actual error, which matches what we do for errors elsewhere, and makes debugging easier. As a result another place needs to look for the prefix now, and not the entire string (since we append the error contents).
1 parent 01be840 commit f9d78d8

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,10 @@ def handle(self, wasm):
15561556
run([in_bin('wasm-opt'), abspath('a.wast')] + FEATURE_OPTS)
15571557

15581558

1559+
# The error shown when a module fails to instantiate.
1560+
INSTANTIATE_ERROR = 'exception thrown: failed to instantiate module'
1561+
1562+
15591563
# Fuzz in a near-identical manner to how we fuzz on ClusterFuzz. This is mainly
15601564
# to see that fuzzing that way works properly (it likely won't catch anything
15611565
# the other fuzzers here catch, though it is possible). That is, running this
@@ -1611,8 +1615,10 @@ def handle(self, wasm):
16111615

16121616
# Verify that we called something. The fuzzer should always emit at
16131617
# least one exported function (unless we've decided to ignore the entire
1614-
# run).
1615-
if output != IGNORE:
1618+
# run, or if the wasm errored during instantiation, which can happen due
1619+
# to a testcase with a segment out of bounds, say).
1620+
if output != IGNORE and not output.startswith(INSTANTIATE_ERROR):
1621+
16161622
assert FUZZ_EXEC_CALL_PREFIX in output
16171623

16181624
def ensure(self):
@@ -1672,7 +1678,7 @@ def handle(self, wasm):
16721678
# to anything.
16731679
return
16741680

1675-
if output.strip() == 'exception thrown: failed to instantiate module':
1681+
if output.startswith(INSTANTIATE_ERROR):
16761682
# We may fail to instantiate the modules for valid reasons, such as
16771683
# an active segment being out of bounds. There is no point to
16781684
# continue in such cases, as no exports are called.

scripts/fuzz_shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function build(binary) {
346346
try {
347347
instance = new WebAssembly.Instance(module, imports);
348348
} catch (e) {
349-
console.log('exception thrown: failed to instantiate module');
349+
console.log('exception thrown: failed to instantiate module: ' + e);
350350
quit();
351351
}
352352

0 commit comments

Comments
 (0)