You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pub fn as_bytes(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.offset as *const u8, self.length as usize) }
}
I'm not sure if this code has an unsound problem, but it calls from_raw_parts without any checks. Although memory is a private mod, I decided to report the issue because I didn't see any //SAFETY to indicate this.
The text was updated successfully, but these errors were encountered:
I'm pretty sure it's not unsound because the only way we create the Regions is from a Vec or from a slice which both should fulfill all the safety requirements.
But it's always a good idea to document this.
Yeah, the idea here is that from_parts upholds all the safety invariants one might need to uphold for us to construct a slice from raw parts.
This is why it's marked as unsafe. If you don't uphold these invariants, you trigger UB. But that's 100% on you because you violated the safety contract.
Admittedly this is very much underdocumented, but you could only have UB here if you violated the safety contract you agreed to when calling from_parts (similarly to Vec::from_raw_parts). And the functions to construct it from a slice or vec are safe since we take ownership and can uphold the safety contract ourselves.
cosmwasm/packages/std/src/memory.rs
Line 105 in b5ee955
I'm not sure if this code has an unsound problem, but it calls
from_raw_parts
without any checks. Althoughmemory
is a private mod, I decided to report the issue because I didn't see any//SAFETY
to indicate this.The text was updated successfully, but these errors were encountered: