Unsound pub API
- Dominant language
- Rust
- Stars
- 46
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
src_kernels/gpu_collider.rs
```rust
pub struct GpuColliderSet {
pub ptr: *const GpuCollider,
pub len: usize,
}
impl GpuColliderSet {
pub fn get(&self, i: usize) -> Option<&GpuCollider> {
if i >= self.len {
None
} else {
unsafe { Some(&*self.ptr.add(i)) }
}
}
pub fn iter(&self) -> GpuColliderIter {
GpuColliderIter {
ptr: self.ptr,
len: self.len,
_marker: PhantomData,
}
}
}
```
At function get, the parameter `i` is checked with a public field `self.len`, which might be altered without limitation. If `self.len` cannot reflect the length of the `self.ptr`, then `*self.ptr.add(i)` will have memory issues like out-of-bound access. The violated safety requirements is [here](https://doc.rust-lang.org/std/primitive.pointer.html#method.add). In Rust, safe function should not cause any memory issue.
Suggestion:
1. mark function with unsafe
2.remove pub from fields
3. add necessary checks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.