Skip to content

Multiple unsound problems in bcf crate #459

Open
@lwz23

Description

@lwz23

unsafe { slice::from_raw_parts(self.inner().samples, self.sample_count() as usize) };

Hello, thank you for your contribution in thin project. Currently, I'm scnning rust project in github, and I notice the following code.

pub struct HeaderView {
    pub inner: *mut htslib::bcf_hdr_t,
}

fn inner(&self) -> htslib::bcf_hdr_t {
        unsafe { *self.inner }
    }

 pub fn samples(&self) -> Vec<&[u8]> {
        let names =
            unsafe { slice::from_raw_parts(self.inner().samples, self.sample_count() as usize) };
        names
            .iter()
            .map(|name| unsafe { ffi::CStr::from_ptr(*name).to_bytes() })
            .collect()
    }

Since samples is a pub function, and inner is also a pub field, bcf is also a pub mod. So I guess this might mean that the user can manipulate the value of inner directly, and if inner is set to an eg. null pointer, it might cause UB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions