Skip to content

Possible unsound public API #7

@charlesxsh

Description

@charlesxsh
    pub fn remove_prefix(&mut self, prefix_len: usize) {
        let len = self.bytes.len();
        let ptr = self.bytes.as_mut_ptr();
        // SAFETY: `bytes` is already a reference bounded by a lifetime
        self.bytes =
            unsafe { std::slice::from_raw_parts_mut(ptr.add(prefix_len), len - prefix_len) };
    }

For the prefix_len, it is used in pointer.add without the sufficient checks, which might cause memory risks.
In Rust, we should not cause any memory issues if merely use safe function.

Suggestions:

  1. adding appropriate checks
  2. make this function unsafe to notify/warn developer/user

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions