Skip to content

Consider mark function as unsafe or add check #5

@charlesxsh

Description

@charlesxsh

Hi there,
In publicly accessible set_data function, set_data accept offset and used in ptr.add, which might letting user/developer, using complete safe API to cause a memory issue(here, it could be out of bound access). In rust, we are expecting no memory issue should be caused by merely safe functions.

vku/src/vma_buffer.rs

Lines 185 to 195 in dc9032c

pub fn set_data<T>(&self, offset: usize, data: &[T]) -> Result<(), Error> {
let Some(ptr) = self.allocation.mapped_ptr() else {
return Err(Error::WriteAttemptToUnmappedBuffer);
};
let mut ptr = ptr.as_ptr() as *mut T;
unsafe {
ptr = ptr.add(offset);
ptr.copy_from_nonoverlapping(data.as_ptr(), data.len());
};
Ok(())

It would be great to consider mark function as unsafe or add appropriate check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions