at version 0.2.1, src/lib.rs:195 and 203
#[inline]
fn get(&self, offset: u32) -> &Trait {
unsafe {
// ! SAFETY: Trait object points to a valid byte representation of this type
&*from_raw_parts(self.bytes.as_ptr().add(offset as usize).cast(), self.vtable)
}
}
#[inline]
fn get_mut(&mut self, offset: u32) -> &mut Trait {
unsafe {
// ! SAFETY: Trait object points to a valid byte representation of this type
let ptr = self.bytes.as_mut_ptr().add(offset as usize).cast();
&mut *from_raw_parts_mut(ptr, self.vtable)
}
}
Safety requirements in https://doc.rust-lang.org/std/primitive.pointer.html#method.add says that "If the computed offset is non-zero, then self must be derived from a pointer to some allocation, and the entire memory range between self and the result must be in bounds of that allocation.". This safety requirement does not hold since both functions accept parameter offset and used in add without checking.
Suggestions:
- Mark both functions as unsafe to notify developers/users the potential memory issues
- Add sufficient checks
at version 0.2.1, src/lib.rs:195 and 203
Safety requirements in https://doc.rust-lang.org/std/primitive.pointer.html#method.add says that "If the computed offset is non-zero, then self must be derived from a pointer to some allocation, and the entire memory range between self and the result must be in bounds of that allocation.". This safety requirement does not hold since both functions accept parameter
offsetand used inaddwithout checking.Suggestions: