This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Description
hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
pub struct VideoDataSourceContext {
pointer: *mut obs_source_frame,
}
impl VideoDataSourceContext {
pub fn from_raw(pointer: *mut obs_source_frame) -> Self {
Self { pointer }
}
pub fn format(&self) -> Option<VideoFormat> {
let raw = unsafe { (*self.pointer).format };
VideoFormat::from_raw(raw).ok()
}
pub fn width(&self) -> u32 {
unsafe { (*self.pointer).width }
}
pub fn height(&self) -> u32 {
unsafe { (*self.pointer).height }
}
pub fn data_buffer(&self, idx: usize) -> *mut u8 {
unsafe { (*self.pointer).data[idx] }
}
pub fn linesize(&self, idx: usize) -> u32 {
unsafe { (*self.pointer).linesize[idx] }
}
pub fn timestamp(&self) -> u64 {
unsafe { (*self.pointer).timestamp }
}
}
Considering that pub mod media, pointer can be passed a null pointer though from_raw, and format timestamp........ are also pub function. I assume that users can directly manipulate this field. This potential situation could result in *self.pointer being dereference a null pointer, and directly dereferencing it might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.
If there is no external usage for VideoDataSourceContext, I suggest it should not marked as pub, at least its field should not marked as pub.