Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EH] Fuzzer: Fix infinite loop with nested exnrefs #7294

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class TranslateToFuzzReader {

Index numAddedFunctions = 0;

// The name of an empty tag.
Name trivialTag;

// RAII helper for managing the state used to create a single function.
struct FunctionCreationContext {
TranslateToFuzzReader& parent;
Expand Down
24 changes: 21 additions & 3 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4825,10 +4825,28 @@ Expression* TranslateToFuzzReader::makeI31Get(Type type) {

Expression* TranslateToFuzzReader::makeThrow(Type type) {
assert(type == Type::unreachable);
if (wasm.tags.empty()) {
addTag();
Tag* tag;
if (trivialNesting) {
// We are nested under a makeTrivial call, so only emit something trivial.
// Get (or create) a trivial tag, so we have no operands (and will not call
// make(), below). Otherwise, we might recurse very deeply if we threw a
// tag that contains an exnref (for which we may end up creating yet another
// throw in a try).
if (!trivialTag) {
auto newTag = builder.makeTag(Names::getValidTagName(wasm, "tag$"),
Signature(Type::none, Type::none));
tag = wasm.addTag(std::move(newTag));
trivialTag = tag->name;
} else {
tag = wasm.getTag(trivialTag);
}
} else {
// Get a random tag, adding a random one if necessary.
if (wasm.tags.empty()) {
addTag();
}
tag = pick(wasm.tags).get();
}
auto* tag = pick(wasm.tags).get();
auto tagType = tag->params();
std::vector<Expression*> operands;
for (auto t : tagType) {
Expand Down
Loading