-
Notifications
You must be signed in to change notification settings - Fork 185
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
Audit: Ensure there are no assumptions that inputs are reasonably sized #292
Comments
I agree with this, it seems like a reasonable idea, and it doesn't seem that hard to do. |
It could be worth to ask the WASI guys to clarify the length argument of I don't think we have similar assumptions in other backends, but I agree it's worth to check to be safe. |
It looks like use of |
implicit in this implementation is the expectation that |
I don't think this is necessary. So not having chunking for the fn foo(buf: &mut [u8]) -> &mut [u8] {
slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len())
} which IIUC is always valid in Rust. |
The fact that a slice can never exceed |
The issue isn't about slices, but about whether a general Regarding the extremely unlikely case that // Ensure `len` is a valid slice length.
let _ = isize::try_from(len).map_err(|_| Error::WHATEVER)?; |
Starting names with |
I like this approach and would be fine with adding it. It's essentially free and properly alerts the user that something has gone wrong in their program. |
It introduces branching, which will be hit every @briansmith |
In most CPUs the branch will be effectively optimized away since it's never taken. If we look at the other implementations, they (almost?) all have a branch of some kind and it doesn't make a difference.
In some sense already it isn't really "necessary" since I think we all acknowledge that the bad situation is extremely unlikely. I encountered this when trying to write the |
I've taken a cursory look over our code base and I think we can close this issue. We can open new issues on case-by-case basis. |
When reviewing PR #279 I noticed at least one instance where we assume that a Rust object is no more than
isize::MAX
bytes long. Although that PR was closed, we should still audit that we do not make that assumption elsewhere in the code. See rust-lang/rust#101899 (comment) and more comments in that issue for evidence that such assumptions aren't generally safe. Arguably the user is doing the wrong thing and triggering UB themselves, but we shouldn't exasperate it.The text was updated successfully, but these errors were encountered: