Skip to content

Commit 5beebc6

Browse files
authored
Fuzzer: Limit ArrayNew sizes most of the time (#5738)
1 parent 97178d0 commit 5beebc6

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

src/tools/fuzzing/fuzzing.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,23 @@ Function* TranslateToFuzzReader::addFunction() {
703703

704704
void TranslateToFuzzReader::addHangLimitChecks(Function* func) {
705705
// loop limit
706-
FindAll<Loop> loops(func->body);
707-
for (auto* loop : loops.list) {
706+
for (auto* loop : FindAll<Loop>(func->body).list) {
708707
loop->body =
709708
builder.makeSequence(makeHangLimitCheck(), loop->body, loop->type);
710709
}
711710
// recursion limit
712711
func->body =
713712
builder.makeSequence(makeHangLimitCheck(), func->body, func->getResults());
713+
// ArrayNew can hang the fuzzer if the array size is massive. This doesn't
714+
// cause an OOM (which the fuzzer knows how to ignore) but it just works for
715+
// many seconds on building the array. To avoid that, limit the size with high
716+
// probability.
717+
for (auto* arrayNew : FindAll<ArrayNew>(func->body).list) {
718+
if (!oneIn(100)) {
719+
arrayNew->size = builder.makeBinary(
720+
AndInt32, arrayNew->size, builder.makeConst(int32_t(1024 - 1)));
721+
}
722+
}
714723
}
715724

716725
void TranslateToFuzzReader::recombine(Function* func) {
Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,44 @@
11
total
2-
[exports] : 4
3-
[funcs] : 7
2+
[exports] : 3
3+
[funcs] : 11
44
[globals] : 16
55
[imports] : 5
66
[memories] : 1
77
[memory-data] : 20
8-
[table-data] : 0
8+
[table-data] : 2
99
[tables] : 1
1010
[tags] : 0
11-
[total] : 600
12-
[vars] : 17
11+
[total] : 549
12+
[vars] : 49
13+
ArrayCopy : 1
1314
ArrayFill : 1
14-
ArrayLen : 3
15-
ArrayNew : 12
15+
ArrayLen : 1
16+
ArrayNew : 14
1617
ArrayNewFixed : 2
17-
ArraySet : 2
18-
AtomicCmpxchg : 1
19-
AtomicFence : 1
20-
AtomicNotify : 1
21-
AtomicRMW : 2
22-
Binary : 73
18+
Binary : 75
2319
Block : 51
24-
Break : 5
25-
Call : 10
26-
CallRef : 3
27-
Const : 162
28-
DataDrop : 1
29-
Drop : 1
30-
GlobalGet : 21
31-
GlobalSet : 20
32-
I31Get : 1
20+
Break : 6
21+
Call : 5
22+
Const : 136
23+
Drop : 2
24+
GlobalGet : 24
25+
GlobalSet : 24
3326
I31New : 4
34-
If : 21
35-
Load : 22
36-
LocalGet : 43
37-
LocalSet : 29
38-
Loop : 4
39-
MemoryFill : 1
27+
If : 16
28+
Load : 18
29+
LocalGet : 54
30+
LocalSet : 31
31+
Loop : 2
4032
Nop : 8
41-
RefAs : 5
42-
RefCast : 2
43-
RefEq : 2
44-
RefFunc : 9
45-
RefIsNull : 4
46-
RefNull : 8
47-
RefTest : 2
48-
Return : 6
49-
Select : 2
50-
Store : 2
51-
StructNew : 18
52-
TupleExtract : 2
33+
RefAs : 3
34+
RefFunc : 4
35+
RefNull : 10
36+
Return : 1
37+
SIMDExtract : 1
38+
Select : 1
39+
StructGet : 2
40+
StructNew : 16
41+
TupleExtract : 3
5342
TupleMake : 4
54-
Unary : 19
55-
Unreachable : 10
43+
Unary : 17
44+
Unreachable : 12

0 commit comments

Comments
 (0)