Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: src/wasm/module-decoder.cc

Issue 2065043002: [wasm] Check for duplicate export names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address ahaas' comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index c753c63983267dff5182bd3306d43f47ebd4b84d..8ea4802ef40ea8baf81c966314582cae47d6b8d4 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -360,6 +360,32 @@ class ModuleDecoder : public Decoder {
exp->func_index = consume_func_index(module, &func);
exp->name_offset = consume_string(&exp->name_length, true);
}
+ // Check for duplicate exports.
+ if (ok() && module->export_table.size() > 1) {
+ std::vector<WasmExport> sorted_exports(module->export_table);
+ const byte* base = start_;
+ auto cmp_less = [base](const WasmExport& a, const WasmExport& b) {
+ // Return true if a < b.
+ uint32_t len = a.name_length;
+ if (len != b.name_length) return len < b.name_length;
+ return memcmp(base + a.name_offset, base + b.name_offset, len) <
+ 0;
+ };
+ std::stable_sort(sorted_exports.begin(), sorted_exports.end(),
+ cmp_less);
+ auto it = sorted_exports.begin();
+ WasmExport* last = &*it++;
+ for (auto end = sorted_exports.end(); it != end; last = &*it++) {
+ DCHECK(!cmp_less(*it, *last)); // Vector must be sorted.
+ if (!cmp_less(*last, *it)) {
+ const byte* pc = start_ + it->name_offset;
+ error(pc, pc,
+ "Duplicate export name '%.*s' for functions %d and %d",
+ it->name_length, pc, last->func_index, it->func_index);
+ break;
+ }
+ }
+ }
break;
}
case WasmSection::Code::Max:
« no previous file with comments | « no previous file | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698