Skip to content

Commit 9308637

Browse files
neelancebradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent cbf90b0 commit 9308637

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

misc/wasm/wasm_exec.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,13 @@
415415
let offset = 4096;
416416

417417
const strPtr = (str) => {
418-
let ptr = offset;
419-
new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + "\0"));
420-
offset += str.length + (8 - (str.length % 8));
418+
const ptr = offset;
419+
const bytes = encoder.encode(str + "\0");
420+
new Uint8Array(mem.buffer, offset, bytes.length).set(bytes);
421+
offset += bytes.length;
422+
if (offset % 8 !== 0) {
423+
offset += 8 - (offset % 8);
424+
}
421425
return ptr;
422426
};
423427

0 commit comments

Comments
 (0)