Commit 126d1d7b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Avoid spread of huge arrays in module builder

I just ran into this when creating a test case. The huge spread caused
a RangeError (stack overflow). It's not causing problems for the tests
we currently have, but let's fix it anyway.

R=ahaas@chromium.org

Change-Id: Ib67f059f2981ccc6239ba4ae05611e20eb3aa191
Reviewed-on: https://chromium-review.googlesource.com/c/1329177
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57429}
parent 434cd5c0
......@@ -74,7 +74,8 @@ class Binary extends Array {
// Emit section length.
this.emit_u32v(section.length);
// Copy the temporary buffer.
this.push(...section);
// Avoid spread because {section} can be huge.
for (let b of section) this.push(b);
}
}
......@@ -209,7 +210,10 @@ class WasmModuleBuilder {
name = this.stringToBytes(name);
var length = new Binary();
length.emit_u32v(name.length + bytes.length);
this.explicit.push([0, ...length, ...name, ...bytes]);
var section = [0, ...length, ...name];
// Avoid spread because {bytes} can be huge.
for (var b of bytes) section.push(b);
this.explicit.push(section);
}
addType(type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment