-
Notifications
You must be signed in to change notification settings - Fork 824
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
Make WasmPtr::get_utf8_string
return String
#1979
Conversation
The old functionality is readded as an `unsafe` method, `WasmPtr::get_utf8_str`. It's important to note that `WasmPtr::get_utf8_string` isn't _entirely_ sound and technically should be marked `unsafe` as well, but this change is a massive improvement over what we had before. For future reference, the reason `WasmPtr::get_utf8_string` still has some soundness issues is that we can't guarantee exclusive access to the memory while parsing in the string, we temporarily hold a `&[u8]` and hope it doesn't get mutated. It's possible to implement this method in a more correct way by copying each byte as we read it into a `Vec` and converting that into a String.
/// | ||
/// Additionally, if `memory` is dynamic, the caller must also ensure that `memory` | ||
/// is not grown while the reference is held. | ||
pub unsafe fn get_utf8_str<'a>(self, memory: &'a Memory, str_len: u32) -> Option<&'a str> { |
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.
Can we mark this function as deprecated? @MarkMcCaskey
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.
We could, but I don't know if we want to! It's dangerous to use, but it is more efficient as it doesn't do any memory allocations, so it's nice to have, it just needs to be used very carefully.
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.
Ok, let's merge then!
bors r+ |
1979: Make `WasmPtr::get_utf8_string` return `String` r=MarkMcCaskey a=MarkMcCaskey The old functionality is readded as an `unsafe` method, `WasmPtr::get_utf8_str`. ~It's important to note that `WasmPtr::get_utf8_string` isn't _entirely_ sound and technically should be marked `unsafe` as well, but this change is a massive improvement over what we had before.~ ~For future reference, the reason `WasmPtr::get_utf8_string` still has some soundness issues is that we can't guarantee exclusive access to the memory while parsing in the string, we temporarily hold a `&[u8]` and hope it doesn't get mutated.~ ~It's possible to implement this method in a more correct way by copying each byte as we read it into a `Vec` and converting that into a String.~ EDIT: fixed in b592ed8; `WasmPtr::get_utf8_string` is sound and uses no `unsafe` internally now. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]>
bors r+ |
Already running a review |
bors r- |
Canceled. |
bors r+ |
1979: Make `WasmPtr::get_utf8_string` return `String` r=MarkMcCaskey a=MarkMcCaskey The old functionality is readded as an `unsafe` method, `WasmPtr::get_utf8_str`. ~It's important to note that `WasmPtr::get_utf8_string` isn't _entirely_ sound and technically should be marked `unsafe` as well, but this change is a massive improvement over what we had before.~ ~For future reference, the reason `WasmPtr::get_utf8_string` still has some soundness issues is that we can't guarantee exclusive access to the memory while parsing in the string, we temporarily hold a `&[u8]` and hope it doesn't get mutated.~ ~It's possible to implement this method in a more correct way by copying each byte as we read it into a `Vec` and converting that into a String.~ EDIT: fixed in b592ed8; `WasmPtr::get_utf8_string` is sound and uses no `unsafe` internally now. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]>
bors r- |
Canceled. |
The old functionality is readded as an
unsafe
method,WasmPtr::get_utf8_str
.It's important to note thatWasmPtr::get_utf8_string
isn't entirely sound and technically should be markedunsafe
as well, but this change is a massive improvement over what we had before.For future reference, the reasonWasmPtr::get_utf8_string
still has some soundness issues is that we can't guarantee exclusive access to the memory while parsing in the string, we temporarily hold a&[u8]
and hope it doesn't get mutated.It's possible to implement this method in a more correct way by copying each byte as we read it into aVec
and converting that into a String.EDIT:
fixed in b592ed8;
WasmPtr::get_utf8_string
is sound and uses nounsafe
internally now.Review