Skip to content

Commit 4563696

Browse files
authored
Fuzzer: The table-get/set imports are sensitive to export changes (#7958)
Mark them as making the wasm untestable in some cases, as we already do for related imports. To avoid too much loss of coverage, export the table less often.
1 parent f8275a5 commit 4563696

3 files changed

Lines changed: 63 additions & 53 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,14 +1247,21 @@ def filter_exports(wasm, output, keep, keep_defaults=True):
12471247
run([in_bin('wasm-metadce'), wasm, '-o', output, '--graph-file', 'graph.json'] + FEATURE_OPTS)
12481248

12491249

1250-
# Check if a wasm file would notice changes to exports. Normally removing an
1251-
# export that is not called, for example, would not be observable, but if the
1252-
# "call-export*" functions are present then such changes can break us.
1250+
# Check if a wasm file would notice normally-unnoticeable changes to exports,
1251+
# such as removing one that is not called.
12531252
def wasm_notices_export_changes(wasm):
1254-
# we could be more precise here and disassemble the wasm to look for an
1255-
# actual import with name "call-export*", but looking for the string should
1256-
# have practically no false positives.
1257-
return b'call-export' in open(wasm, 'rb').read()
1253+
wat = run([in_bin('wasm-dis'), wasm] + FEATURE_OPTS)
1254+
1255+
if '(import "fuzzing-support" "call-export' in wat:
1256+
# The call-export* imports are sensitive to the number and identity of
1257+
# exports.
1258+
return True
1259+
1260+
if '(import "fuzzing-support" "table-' in wat and '(export "table" (table ' in wat:
1261+
# The table-get/set imports are sensitive to the "table" export.
1262+
return True
1263+
1264+
return False
12581265

12591266

12601267
# Fuzz the interpreter with --fuzz-exec -tnh. The tricky thing with traps-never-

src/tools/fuzzing/fuzzing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,14 @@ void TranslateToFuzzReader::addImportTableSupport() {
10621062
return;
10631063
}
10641064

1065+
// Do not always export the table even if we can, as it inhibits some things
1066+
// in the fuzzer (with this export, the wasm becomes more sensitive to
1067+
// otherwise inconsequential changes: calling the table-get/set imports is
1068+
// influenced by the existence of this export).
1069+
if (!random.oneIn(3)) {
1070+
return;
1071+
}
1072+
10651073
// Export the table.
10661074
wasm.addExport(
10671075
builder.makeExport("table", funcrefTableName, ExternalKind::Table));
Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
Metrics
22
total
3-
[exports] : 8
4-
[funcs] : 12
3+
[exports] : 12
4+
[funcs] : 19
55
[globals] : 26
6-
[imports] : 12
6+
[imports] : 10
77
[memories] : 1
88
[memory-data] : 16
9-
[table-data] : 1
9+
[table-data] : 14
1010
[tables] : 2
11-
[tags] : 2
12-
[total] : 724
13-
[vars] : 58
14-
ArrayNew : 1
15-
ArrayNewFixed : 4
16-
Binary : 31
17-
Block : 141
18-
BrOn : 1
19-
Break : 9
20-
Call : 28
21-
Const : 166
22-
Drop : 69
23-
GlobalGet : 47
24-
GlobalSet : 34
11+
[tags] : 1
12+
[total] : 574
13+
[vars] : 67
14+
ArrayNewFixed : 8
15+
Binary : 26
16+
Block : 93
17+
BrOn : 2
18+
Break : 2
19+
Call : 24
20+
CallRef : 1
21+
Const : 110
22+
Drop : 18
23+
GlobalGet : 51
24+
GlobalSet : 44
2525
I31Get : 2
26-
If : 20
27-
Load : 6
28-
LocalGet : 8
29-
LocalSet : 17
30-
Loop : 5
31-
Nop : 2
32-
Pop : 5
33-
RefCast : 1
34-
RefEq : 5
35-
RefFunc : 2
36-
RefI31 : 14
37-
RefNull : 9
38-
Return : 6
39-
SIMDExtract : 1
40-
Select : 3
41-
Store : 1
42-
StringConst : 9
43-
StringEncode : 1
44-
StringEq : 1
45-
StringMeasure : 1
46-
StructNew : 11
47-
TableSet : 1
48-
Throw : 2
49-
Try : 5
50-
TryTable : 5
51-
TupleExtract : 2
52-
TupleMake : 7
26+
If : 26
27+
Load : 2
28+
LocalGet : 7
29+
LocalSet : 6
30+
Loop : 3
31+
Nop : 8
32+
RefAs : 1
33+
RefEq : 1
34+
RefFunc : 16
35+
RefI31 : 3
36+
RefNull : 18
37+
RefTest : 3
38+
Return : 9
39+
Select : 1
40+
Store : 2
41+
StringConst : 13
42+
StringMeasure : 3
43+
StructNew : 13
44+
Try : 2
45+
TryTable : 3
46+
TupleExtract : 1
47+
TupleMake : 5
5348
Unary : 24
54-
Unreachable : 17
49+
Unreachable : 23

0 commit comments

Comments
 (0)