-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
String::write_str overflows to WasmRefCell.borrow #4386
Comments
I don't see any. Looks fine to me.
I have no idea unfortunately. I'm much more inclined to think there is a bug in If you somehow manage to get it down to a small reproducible example then I would like to take a stab at it myself! |
@daxpedda I would try to create a minimal reproducible code snippet. Is there a good way to get the address of an rust object and print it in console.log so that I can verify if certain faulty allocation is still happening after I remove certain amount of code? |
See |
Are there multiple implementation of |
Summary
I am building a relatively simple wasm using wasm-bindgen 0.2.99 and run is via Vite-React on Chrome, where I expose the following rust structs to JS through wasm-bindgen:
The wasm runs just fine, except sometimes I got
memory out of bound
,recursive use of an object detected which would lead to unsafe aliasing in rust
,table index out of bound
exceptions.At first I thought it was certain borrow rules were not observed in my JavaScript code, that I really tried to borrow_mut from an object that was already borrowed. Then I realised it didn't make sense because I am not using webWorker, and I don't have async code in my rust codebase, so this shouldn't happened.
Then I drilled down on the prominent error
recursive use of an object detected which would lead to unsafe aliasing in rust
, and it turned out that it was complaining because the borrow count is not 0, and strangely, every time when it fails, the borrow count is a constant (1919903810), but it is far from i32::MAX, so it wasn't a recursive mute borrow.Which leaves the possibilities that either the
ChordProgressionManager
was indeed readonly-ly borrowed 1919903810 times, or there were some illegal memory copies brewing. After some painstakingly breakpoint witch-hunts, I finally pinpoint the unexpected memory copy occurs infunc $<alloc::string::String as core::fmt::Write>::write_str::hf0fb92960288353a
, where there is acall $memcpy
. Specifically, it was copying 17 characters"Initial Chord is "
to the data field of a String, so I assume somehow there is a String's allocation incorrectly overlaps withWasmRefCell
of theChordProgressionManager
.So my questions are:
Let me know if more details is needed. Thanks in advance on spending time looking into this writeup!
The text was updated successfully, but these errors were encountered: