Skip to content

Unsound struct API #232

@charlesxsh

Description

@charlesxsh

src/parser.rs:

pub struct LineReader<'a> {
    pub buf: &'a [u8],
    line: usize,
}

impl<'a> LineReader<'a> {
        ...

        pub fn parse_numbers(&self) -> Result<(u32, u32, u32, u32)> {
                // we know that line is beginning with "@@ -"
                let buf = unsafe { self.buf.get_unchecked(4..) };
                ...
        }
}

Hi there, the struct LineReader has a public field buf, the safe public function parse_numbers use it with unsafe function get_unchecked, which violated the safety requirements mentioned in here. This could cause memory issues if buf changed to other array less then 4, even when no unsafe function involved.

Suggestion:

  1. make buf private
  2. Or make parse_numbers to unsafe.

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