Skip to content

Commit baa841a

Browse files
authored
[Custom Descriptors] Handle traps in instantiation in Merge fuzz handler (#7784)
With custom descriptors, it's possible for instantiation to trap when a `struct.new` in a global initialiizer receives a null descriptor. Update the Merge fuzz handler so that if the randomly generated second module traps in instantion, it checks that the merged module also traps in instantiation. As a drive-by, remove some unnecessary feature flags passed to wasm-merge and wasm-opt.
1 parent 1d6320a commit baa841a

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

scripts/fuzz_opt.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,20 @@ def wasm_has_duplicate_tags(wasm):
14051405
return binary.count(b'jstag') >= 2 or binary.count(b'wasmtag') >= 2
14061406

14071407

1408+
# Detect whether there is a trap reported before an export call in the output.
1409+
def traps_in_instantiation(output):
1410+
trap_index = output.find(TRAP_PREFIX)
1411+
if trap_index == -1:
1412+
# In "fixed" output, traps are replaced with *exception*.
1413+
trap_index = output.find('*exception*')
1414+
if trap_index == -1:
1415+
return False
1416+
call_index = output.find(FUZZ_EXEC_CALL_PREFIX)
1417+
if call_index == -1:
1418+
return True
1419+
return trap_index < call_index
1420+
1421+
14081422
# Tests wasm-merge
14091423
class Merge(TestCaseHandler):
14101424
frequency = 0.15
@@ -1455,7 +1469,7 @@ def handle(self, wasm):
14551469
merged = abspath('merged.wasm')
14561470
run([in_bin('wasm-merge'), wasm, 'first',
14571471
abspath('second.wasm'), 'second', '-o', merged,
1458-
'--skip-export-conflicts'] + FEATURE_OPTS + ['-all'])
1472+
'--skip-export-conflicts', '-all'])
14591473

14601474
if wasm_has_duplicate_tags(merged):
14611475
note_ignored_vm_run('dupe_tags')
@@ -1464,14 +1478,32 @@ def handle(self, wasm):
14641478
# sometimes also optimize the merged module
14651479
if random.random() < 0.5:
14661480
opts = get_random_opts()
1467-
run([in_bin('wasm-opt'), merged, '-o', merged, '-all'] + FEATURE_OPTS + opts)
1481+
run([in_bin('wasm-opt'), merged, '-o', merged, '-all'] + opts)
14681482

14691483
# verify that merging in the second module did not alter the output.
14701484
output = run_bynterp(wasm, ['--fuzz-exec-before', '-all'])
14711485
output = fix_output(output)
1486+
second_output = run_bynterp(second_wasm, ['--fuzz-exec-before', '-all'])
1487+
second_output = fix_output(second_output)
14721488
merged_output = run_bynterp(merged, ['--fuzz-exec-before', '-all'])
14731489
merged_output = fix_output(merged_output)
14741490

1491+
# If the second module traps in instantiation, then the merged module
1492+
# must do so as well, regardless of what the first module does. (In
1493+
# contrast, if the first module traps in instantiation, then the normal
1494+
# checks below will ensure the merged module does as well.)
1495+
if traps_in_instantiation(second_output) and \
1496+
not traps_in_instantiation(output):
1497+
# The merged module should also trap in instantiation, but the
1498+
# exports will not be called, so there's nothing else to compare.
1499+
if not traps_in_instantiation(merged_output):
1500+
raise Exception('expected merged module to trap during ' +
1501+
'instantiation because second module traps ' +
1502+
'during instantiation')
1503+
compare(merged_output, second_output, 'Merge: second module traps' +
1504+
' in instantiation')
1505+
return
1506+
14751507
# a complication is that the second module's exports are appended, so we
14761508
# have extra output. to handle that, just prune the tail, so that we
14771509
# only compare the original exports from the first module.

0 commit comments

Comments
 (0)