Skip to content

Commit b671b6c

Browse files
authored
Fuzzer: Fix up null outputs in wasm2js optimized builds (#6374)
This is fallout from #6310 where we moved to use fuzz_shell.js for all fuzzing purposes. That script doesn't know wasm types, all it has on the JS side is the number of arguments to a function, and it passes in null for them all regardless of their type. That normally works fine - null is cast to the right type upon use - but in wasm2js optimized builds we can remove casts, which can make that noticeable.
1 parent df1044f commit b671b6c

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,21 @@ def fix_output_for_js(x):
10591059
# start with the normal output fixes that all VMs need
10601060
x = fix_output(x)
10611061

1062+
# replace null with 0. the fuzzing harness passes in nulls instead
1063+
# the specific type of a parameter (since null can be cast to
1064+
# anything without issue, and all fuzz_shell.js knows on the JS side
1065+
# is the number of parameters), which can be noticeable in a
1066+
# situation where we optimize and remove casts, like here:
1067+
#
1068+
# function foo(x) { return x | 0; }
1069+
#
1070+
# When optimizing we can remove that | 0, which is valid if the
1071+
# input is valid, but as we said, the fuzz harness passes in a value
1072+
# of the wrong type - which would be cast on use, but if we remove
1073+
# the casts, we end up returning null here and not 0, which the
1074+
# fuzzer can notice.
1075+
x = re.sub(r' null', ' 0', x)
1076+
10621077
# check if a number is 0 or a subnormal, which is basically zero
10631078
def is_basically_zero(x):
10641079
# to check if something is a subnormal, compare it to the largest one

0 commit comments

Comments
 (0)