Skip to content

Fix mis-hinting latin1+utf16 strings across 32- and 64-bit memories - #772

Open
fitzgen wants to merge 1 commit into
WebAssembly:mainfrom
fitzgen:fix-latin1+utf16-string-hint-across-32-and-64-bit-memories
Open

fitzgen wants to merge 1 commit into
WebAssembly:mainfrom
fitzgen:fix-latin1+utf16-string-hint-across-32-and-64-bit-memories

Conversation

@fitzgen

@fitzgen fitzgen commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

tagged_code_units used the source memory's tag, but store_string_into_range decoded it with the target memory's tag, so passing strings between 32- and 64-bit memories checked the wrong tag and this was guest-observable due to the wrong realloc calls getting made.

This is fixed by having load_string_from_range eagerly decode and remember the String's encoding hint and store_string_into_range to just use that hint, rather than try to read the hint itself.

Additionally, I made a class StringHint(Enum) so that it is more clear what the hint cases are, and to differentiate dynamic hints from actual encodings and the string-encoding canon option values.

`tagged_code_units` used the source memory's tag, but `store_string_into_range`
decoded it with the target memory's tag, so passing strings between 32- and
64-bit memories checked the wrong tag and this was guest-observable due to the
wrong `realloc` calls getting made.

This is fixed by having `load_string_from_range` eagerly decode and remember the
`String`'s encoding hint and `store_string_into_range` to just use that hint,
rather than try to read the hint itself.

Additionally, I made a `class StringHint(Enum)` so that it is more clear what
the hint cases are, and to differentiate dynamic hints from actual encodings and
the `string-encoding` canon option values.

@lukewagner lukewagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! This is a nicer factoring of the problem anyways.

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-bytecodealliance__wasmtime that referenced this pull request Nov 24, 2026
…bit memories (bytecodealliance#15450)

* Fix utf16 hinting for `latin1+utf16` strings sent between 32- and 64-bit memories

This is the Wasmtime version of this bug fix in the CM spec:
WebAssembly/component-model#772

* Address review feedback
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.

2 participants