Skip to content

fix: size the argv buffer in UTF-8 bytes, not UTF-16 code units - #113

Open
madeiragab wants to merge 1 commit into
bjorn3:mainfrom
madeiragab:fix/argv-buffer-size-in-bytes
Open

fix: size the argv buffer in UTF-8 bytes, not UTF-16 code units#113
madeiragab wants to merge 1 commit into
bjorn3:mainfrom
madeiragab:fix/argv-buffer-size-in-bytes

Conversation

@madeiragab

Copy link
Copy Markdown

args_get writes each argument with TextEncoder, so the bytes that reach guest memory are UTF-8. args_sizes_get computes the buffer size with arg.length, which counts UTF-16 code units.

For ASCII the two agree and nothing happens. A single non-ASCII character makes the reported size smaller than what args_get actually writes, so the write runs past the end of the guest's argv buffer and corrupts whatever follows it.

environ_sizes_get, a few lines below, already measures with TextEncoder. This makes the argv path match it.

How I ran into it: a Rust database compiled to wasm32-wasip1, driven from the page, taking SQL as a command-line argument. One accented character inside a SQL comment corrupted the next argument in guest memory - it surfaced as the engine complaining about a column named C that nobody had written. Passing the script through stdin instead of argv worked around it on my side, which is what pointed at the argv path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant