bakkesmod-rust icon indicating copy to clipboard operation
bakkesmod-rust copied to clipboard

Possible public unsafe API

Open charlesxsh opened this issue 6 months ago • 0 comments

pub struct RLArray<T: UnrealPointer> {
    pub data: *mut usize,
    count: u32,
    max: u32,
    phantom: PhantomData<T>
}

 pub fn get(&self, index: isize) -> T {
        unsafe { 
            let ptr = self.data.offset(index);
            T::from_ptr(*ptr)
        }
    }

Hi there, publicly possible RLArray::get calculate the pointer using the parameter index and public field data without sufficient checks, which might cause memory issues. In Rust, we should not cause any memory issues by merely using safe functions.

Suggestions:

  1. make the field private
  2. add sufficient check
  3. mark this function unsafe

charlesxsh avatar May 23 '25 04:05 charlesxsh