summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-02-12 13:09:31 -0800
committerGitHub <noreply@github.com>2024-02-12 13:09:31 -0800
commit34d35ae7c0a8e42f94fd02b4b1aa64aec3621a05 (patch)
treec7fbb8383fba415d41f3aaeef06b8c553b3d130c /src/tools
parent1e9838e7f9e3777e12e4f221a3281e73edce1c15 (diff)
downloadbinaryen-34d35ae7c0a8e42f94fd02b4b1aa64aec3621a05.tar.gz
binaryen-34d35ae7c0a8e42f94fd02b4b1aa64aec3621a05.tar.bz2
binaryen-34d35ae7c0a8e42f94fd02b4b1aa64aec3621a05.zip
Fuzzer: Do not emit huge and possibly non-validating tables (#6288)
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/fuzzing/fuzzing.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 07464af9d..2b776144d 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -513,6 +513,23 @@ void TranslateToFuzzReader::finalizeTable() {
}
table->initial = std::max(table->initial, maxOffset);
});
+
+ // The code above raises table->initial to a size large enough to accomodate
+ // all of its segments, with the intention of avoiding a trap during
+ // startup. However a single segment of (say) size 4GB would have a table of
+ // that size, which will use a lot of memory and execute very slowly, so we
+ // prefer in the fuzzer to trap on such a thing. To achieve that, set a
+ // reasonable limit for the maximum table size.
+ //
+ // This also avoids an issue that arises from table->initial being an
+ // Address (64 bits) but Table::kMaxSize being an Index (32 bits), as a
+ // result of which we need to clamp to Table::kMaxSize as well in order for
+ // the module to validate (but since we are clamping to a smaller value,
+ // there is no need).
+ const Address ReasonableMaxTableSize = 10000;
+ table->initial = std::min(table->initial, ReasonableMaxTableSize);
+ assert(ReasonableMaxTableSize <= Table::kMaxSize);
+
table->max = oneIn(2) ? Address(Table::kUnlimitedSize) : table->initial;
// Avoid an imported table (which the fuzz harness would need to handle).
table->module = table->base = Name();