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.
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