diff options
author | Alon Zakai <azakai@google.com> | 2021-07-22 15:58:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-22 15:58:04 -0700 |
commit | 464ddbe5faf151b5ef50d56d00ad442ac76620a6 (patch) | |
tree | f504c2b21a69fa709ce81d613ddf979b33e3392b /src | |
parent | 90545189ce4f790c798e83c1e65afb70f228d176 (diff) | |
download | binaryen-464ddbe5faf151b5ef50d56d00ad442ac76620a6.tar.gz binaryen-464ddbe5faf151b5ef50d56d00ad442ac76620a6.tar.bz2 binaryen-464ddbe5faf151b5ef50d56d00ad442ac76620a6.zip |
wasm-reduce: Avoid a crash where function names change after tryToRemoveFunctions (#4013)
tryToRemoveFunctions() will reload the wasm from binary if it fails to
optimize, and without the names section we don't have a guarantee on the
names being the same after that. And then tryToEmptyFunctions would
look for a name, and crash.
In the reverse order there is no risk, as tryToEmptyFunctions does not
reload the wasm from binary, it carefully undoes what it tried to do when
it fails.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-reduce.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index b36891d5b..29218de6f 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -890,9 +890,10 @@ struct Reducer if (names.size() == 0) { continue; } - // Try to remove functions, and if that fails, try to at least empty out - // their bodies. - justReduced = tryToRemoveFunctions(names) || tryToEmptyFunctions(names); + // Try to remove functions and/or empty them. Note that + // tryToRemoveFunctions() will reload the module if it fails, which means + // function names may change - for that reason, run it second. + justReduced = tryToEmptyFunctions(names) || tryToRemoveFunctions(names); if (justReduced) { noteReduction(names.size()); i += skip; |