diff options
author | Jacob Gravelle <jgravelle@google.com> | 2018-02-06 11:17:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-06 11:17:37 -0800 |
commit | a3232460dd4dc63b0ed39a68f0bebecc805572d4 (patch) | |
tree | 03b8838a826c7974434368e634723171f335a317 /src | |
parent | a85be9781620696b79d0efd694605f608417098d (diff) | |
download | binaryen-a3232460dd4dc63b0ed39a68f0bebecc805572d4.tar.gz binaryen-a3232460dd4dc63b0ed39a68f0bebecc805572d4.tar.bz2 binaryen-a3232460dd4dc63b0ed39a68f0bebecc805572d4.zip |
Dedupe function names when reading a binary (#1396)
* Dedupe function names when reading a binary
* More robust name deduplication, use .s instead of _s
* Add name-duplicated wasm binaries
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 188c2bc17..0fed49729 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2192,9 +2192,15 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) { continue; } auto num = getU32LEB(); + std::set<Name> usedNames; for (size_t i = 0; i < num; i++) { auto index = getU32LEB(); - auto name = getInlineString(); + auto rawName = getInlineString(); + auto name = rawName; + // De-duplicate names by appending .1, .2, etc. + for (int i = 1; !usedNames.insert(name).second; ++i) { + name = rawName.str + std::string(".") + std::to_string(i); + } // note: we silently ignore errors here, as name section errors // are not fatal. should we warn? auto numFunctionImports = functionImports.size(); @@ -2202,13 +2208,8 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) { functionImports[index]->name = name; } else if (index - numFunctionImports < functions.size()) { functions[index - numFunctionImports]->name = name; - } - } - // disallow duplicate names - std::set<Name> functionNames; - for (auto* func : functions) { - if (!functionNames.insert(func->name).second) { - throw ParseException("duplicate function name: " + std::string(func->name.str)); + } else { + throw ParseException("index out of bounds: " + std::string(name.str)); } } if (pos != subsectionPos + subsectionSize) { |