From: Richard Musiol Date: Thu, 25 Apr 2019 08:55:49 +0000 (+0200) Subject: misc/wasm: fix command line arguments containing multi-byte characters X-Git-Tag: go1.13beta1~507 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9308637e3c2babcb3695d9f9673cf2a2b840362d;p=gostls13.git misc/wasm: fix command line arguments containing multi-byte characters Command line arguments containing multi-byte characters were causing go_js_wasm_exec to crash (RangeError: Source is too large), because their byte length was not handled correctly. This change fixes the bug. Fixes #31645. Change-Id: I7860ebf5b12da37d9d0f43d4b6a22d326a90edaf Reviewed-on: https://go-review.googlesource.com/c/go/+/173877 Run-TryBot: Richard Musiol TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke Reviewed-by: Brad Fitzpatrick --- diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index 29427d91e5..a1d88e6eac 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -415,9 +415,13 @@ let offset = 4096; const strPtr = (str) => { - let ptr = offset; - new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + "\0")); - offset += str.length + (8 - (str.length % 8)); + const ptr = offset; + const bytes = encoder.encode(str + "\0"); + new Uint8Array(mem.buffer, offset, bytes.length).set(bytes); + offset += bytes.length; + if (offset % 8 !== 0) { + offset += 8 - (offset % 8); + } return ptr; };