Title: [210203] trunk
Revision
210203
Author
sbar...@apple.com
Date
2016-12-28 19:10:04 -0800 (Wed, 28 Dec 2016)

Log Message

WebAssembly: Don't allow duplicate export names
https://bugs.webkit.org/show_bug.cgi?id=166490
<rdar://problem/29815000>

Reviewed by Keith Miller.

JSTests:

* wasm.yaml:
* wasm/function-tests/invalid-duplicate-export.js: Added.

Source/_javascript_Core:

* wasm/WasmModuleParser.cpp:

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (210202 => 210203)


--- trunk/JSTests/ChangeLog	2016-12-29 00:18:44 UTC (rev 210202)
+++ trunk/JSTests/ChangeLog	2016-12-29 03:10:04 UTC (rev 210203)
@@ -1,5 +1,16 @@
 2016-12-28  Saam Barati  <sbar...@apple.com>
 
+        WebAssembly: Don't allow duplicate export names
+        https://bugs.webkit.org/show_bug.cgi?id=166490
+        <rdar://problem/29815000>
+
+        Reviewed by Keith Miller.
+
+        * wasm.yaml:
+        * wasm/function-tests/invalid-duplicate-export.js: Added.
+
+2016-12-28  Saam Barati  <sbar...@apple.com>
+
         WebAssembly: Implement grow_memory and current_memory
         https://bugs.webkit.org/show_bug.cgi?id=166448
         <rdar://problem/29803676>

Added: trunk/JSTests/wasm/function-tests/invalid-duplicate-export.js (0 => 210203)


--- trunk/JSTests/wasm/function-tests/invalid-duplicate-export.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/invalid-duplicate-export.js	2016-12-29 03:10:04 UTC (rev 210203)
@@ -0,0 +1,19 @@
+import Builder from '../Builder.js';
+import * as assert from '../assert.js';
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Function().End()
+        .Export()
+            .Function("foo")
+            .Function("foo")
+        .End()
+        .Code()
+            .Function("foo", {params: [], ret: "void"})
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    assert.throws(() => new WebAssembly.Module(bin), WebAssembly.CompileError, "WebAssembly.Module doesn't parse at byte 31 / 39: duplicate export: 'foo'");
+}

Modified: trunk/JSTests/wasm.yaml (210202 => 210203)


--- trunk/JSTests/wasm.yaml	2016-12-29 00:18:44 UTC (rev 210202)
+++ trunk/JSTests/wasm.yaml	2016-12-29 03:10:04 UTC (rev 210203)
@@ -68,7 +68,7 @@
   cmd: runWebAssemblySpecTest :normal
 
 - path: wasm/spec-tests/exports.wast.js
-  cmd: runWebAssemblySpecTest :skip
+  cmd: runWebAssemblySpecTest :normal
 
 - path: wasm/spec-tests/f32.wast.js
   cmd: runWebAssemblySpecTest :normal

Modified: trunk/Source/_javascript_Core/ChangeLog (210202 => 210203)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-29 00:18:44 UTC (rev 210202)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-29 03:10:04 UTC (rev 210203)
@@ -1,5 +1,15 @@
 2016-12-28  Saam Barati  <sbar...@apple.com>
 
+        WebAssembly: Don't allow duplicate export names
+        https://bugs.webkit.org/show_bug.cgi?id=166490
+        <rdar://problem/29815000>
+
+        Reviewed by Keith Miller.
+
+        * wasm/WasmModuleParser.cpp:
+
+2016-12-28  Saam Barati  <sbar...@apple.com>
+
         Unreviewed. Fix jsc.cpp build error.
 
         * jsc.cpp:

Modified: trunk/Source/_javascript_Core/wasm/WasmModuleParser.cpp (210202 => 210203)


--- trunk/Source/_javascript_Core/wasm/WasmModuleParser.cpp	2016-12-29 00:18:44 UTC (rev 210202)
+++ trunk/Source/_javascript_Core/wasm/WasmModuleParser.cpp	2016-12-29 03:10:04 UTC (rev 210203)
@@ -371,6 +371,7 @@
     WASM_PARSER_FAIL_IF(exportCount == std::numeric_limits<uint32_t>::max(), "Export section's count is too big ", exportCount);
     WASM_PARSER_FAIL_IF(!m_result.module->exports.tryReserveCapacity(exportCount), "can't allocate enough memory for ", exportCount, " exports");
 
+    HashSet<String> exportNames;
     for (uint32_t exportNumber = 0; exportNumber < exportCount; ++exportNumber) {
         Export exp;
         uint32_t fieldLen;
@@ -378,6 +379,8 @@
 
         WASM_PARSER_FAIL_IF(!parseVarUInt32(fieldLen), "can't get ", exportNumber, "th Export's field name length");
         WASM_PARSER_FAIL_IF(!consumeUTF8String(fieldString, fieldLen), "can't get ", exportNumber, "th Export's field name of length ", fieldLen);
+        WASM_PARSER_FAIL_IF(exportNames.contains(fieldString), "duplicate export: '", fieldString, "'");
+        exportNames.add(fieldString);
         exp.field = Identifier::fromString(m_vm, fieldString);
 
         WASM_PARSER_FAIL_IF(!parseExternalKind(exp.kind), "can't get ", exportNumber, "th Export's kind, named '", fieldString, "'");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to