Twinklebear / embree-rs

Rust bindings to Embree 3
MIT License
34 stars 13 forks source link

Unsound usages of `VecFromRawParts` #25

Open llooFlashooll opened 4 weeks ago

llooFlashooll commented 4 weeks ago

Hi, I am scanning the embree-rs in the latest version with my own static analyzer tool.

Unsafe conversion found at: src/lib.rs#L88

   unsafe {
      let mem = alloc::alloc(layout);
      assert_eq!((mem as usize) % 16, 0);
      Vec::<T>::from_raw_parts(mem as *mut T, len, len)
   }

This unsound implementation of Vec::from_raw_parts would create a dangling pointer issues if the mem is dropped automatically or is empty. The 'mem::forget' function can be used to avoid the issue.

This would potentially cause undefined behaviors in Rust. If we further manipulate the problematic converted types, it would potentially lead to different consequences such as uaf or double free. I am reporting this issue for your attention.