UB with impl FromWasmAbi for char
when unpaired surrogate is given
#2269
Labels
breaking-change
Tracking breaking changes for the next major version bump (if ever)
Describe the Bug
Wasm-bindgen assumes the "char" (which is a JavaScript
String
) to be converted is always valid and useschar::from_u32_unchecked
. However the JSString
may contain a single "char" of an unpaired surrogate (for example when the JS code usescharAt
), in which usingchar::from_u32_unchecked
with it creates an invalidchar
and causes UB.Steps to Reproduce
Expected Behavior
I don't have an idea what behaviour would be the best. Probably use U+FFFD like how strings are handled? Perhaps if the type is
Option<char>
it should usechar::from_u32
instead, but then this might cause ambiguity betweennull
-ish and invalid char.Actual Behavior
An invalid
char
is produced.Additional Context
The text was updated successfully, but these errors were encountered: