fix: size the argv buffer in UTF-8 bytes, not UTF-16 code units - #113
Open
madeiragab wants to merge 1 commit into
Open
fix: size the argv buffer in UTF-8 bytes, not UTF-16 code units#113madeiragab wants to merge 1 commit into
madeiragab wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
args_getwrites each argument withTextEncoder, so the bytes that reach guest memory are UTF-8.args_sizes_getcomputes the buffer size witharg.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_getactually 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 withTextEncoder. 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 namedCthat 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.