-
Notifications
You must be signed in to change notification settings - Fork 19
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
bug: critical DOUBLE-FREE problem for all calls to post() #7
Comments
Hello, thanks for the write-up! it is really great! The only part I guess you got a bit confused about: that's there is two different types/variant inside the
So, unless you wrap your buffer the Hope that was clear! as that's far as I understand, from reading some internal code of the dartvm. |
Also, on item 2 above the buffer is forgotten by the use of |
I think you are right! The DartNativeTypedData has different implementations compared with DartNativeExternalTypedData and I get confused. Maybe I can make a PR, such that we try to refactor the code to put the relevant code together? Then the code can be easier to understand and thus maintain. |
PRs are always welcome! |
Please correct me if I am wrong. Suppose we call
post
with some vec of u8.Looking at
https://github.com/sunshine-protocol/allo-isolate/blob/d10c582aba2a41f65889f1270f009b4c9a4c899b/src/lib.rs#L117-L125
the logic is:
When
drop(boxed_obj)
it will call the following:https://github.com/sunshine-protocol/allo-isolate/blob/d10c582aba2a41f65889f1270f009b4c9a4c899b/src/ffi.rs#L152-L184
So, since it is a DartTypedData, will call
let _ = unsafe { Vec::from_raw_parts(...) }
. Then when the_
variable leaves the scope, Rust will drop that Vec. In other words, the big array in memory is dropped (once) here.However, on the other hand, consider what Dart_PostCObject says: dart-lang/sdk#47270 (comment)
To begin with, there do definitely exist a possible issue here: #6
However, more critical issue is double free. Notice that, the callback tied with typed data will finally be called (if Dart_PostCObject returns true - which is most of the cases). And we do https://github.com/sunshine-protocol/allo-isolate/blob/d10c582aba2a41f65889f1270f009b4c9a4c899b/src/into_dart.rs#L205 . In other words, we call
deallocate_rust_buffer
which isdrop(Vec::from_raw_parts(ptr, len, len));
. Hey, this is another free of the big array!So we have double free! Dangerous!
Possibly related: #3
@jerel @shekohex
The text was updated successfully, but these errors were encountered: