-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JS<->WASM string marshaling crash #42486
Conversation
Fix passing strings across the boundary Fix JS strings being truncated at the first null when passed to mono
This likely fixes #41604 along with another non-github-tracked issue involving large strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM. Thanks a lot!
var buffer = Module._malloc ((string.length + 1) * 2); | ||
var buffer16 = (buffer / 2) | 0; | ||
for (var i = 0; i < string.length; i++) | ||
Module.HEAP16[buffer16 + i] = string.charCodeAt (i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Is this file intended to follow Mono conventions? If so, space before the [
here and the next line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, though I don't know if we follow that convention for the JS. I can make it match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll correct this in the larger bindings optimization PR, didn't want to let a formatting change delay the merge on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't string[i]
access generally faster than charCodeAt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string[i] in JS returns a single-character string
/backport to release/5.0-rc2 |
Started backporting to release/5.0-rc2: https://github.com/dotnet/runtime/actions/runs/262527073 |
@kg backporting to release/5.0-rc2 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix passing mono object ptrs to bound functions Fix passing strings across the boundary Fix JS strings being truncated at the first null when passed to mono
Applying: Add new string conv wrapper
error: sha1 information is lacking or useless (src/mono/wasm/runtime/binding_support.js).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Add new string conv wrapper
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
This adds another allocation+copy for that marshal case, what was the failure case before? |
Random out-of-bounds memory accesses / memory corruptions, and truncation at the first null |
Fix JS strings being truncated at the first null when passed to mono Fix crashes when moving large strings across the JS<->WASM boundary
* Fix an api regression introduced in #42486 * Update src/mono/wasm/runtime/binding_support.js a number it is Co-authored-by: Ankit Jain <[email protected]> Co-authored-by: Ankit Jain <[email protected]>
Fix JS strings being truncated at the first null when passed to mono Fix crashes when moving large strings across the JS<->WASM boundary
) Co-authored-by: Katelyn Gadd <[email protected]>
Under some circumstances passing strings across the JS<->WASM boundary will crash or corrupt memory. We also currently truncate strings at the first embedded null, which is wrong. This PR fixes both.