Hi, I import the crate of quick-protobuf v0.8.1 and accidentally trigger the error with read_packed_fixed::<u32>. However, I found that the code shown in crates.io is different from the one on Github. It seems that the code on crates.io is newer than here?
pub fn read_packed_fixed<'a, M>(&mut self, bytes: &'a [u8]) -> Result<&'a [M]> {
let len = self.read_varint32(bytes)? as usize;
if self.len() < len {
return Err(Error::UnexpectedEndOfBuffer);
}
let n = len / ::core::mem::size_of::<M>();
let slice = unsafe {
::core::slice::from_raw_parts(
bytes.get_unchecked(self.start) as *const u8 as *const M,
n,
)
};
self.start += len;
Ok(slice)
}
The code allow to set arbitrary type to generic type without trait bound, which could cause to undefined behavior here.
See crate code here: https://docs.rs/crate/quick-protobuf/0.8.1/source/src/reader.rs#443-462
Hi, I import the crate of quick-protobuf v0.8.1 and accidentally trigger the error with
read_packed_fixed::<u32>. However, I found that the code shown in crates.io is different from the one on Github. It seems that the code on crates.io is newer than here?The code allow to set arbitrary type to generic type without trait bound, which could cause to undefined behavior here.
See crate code here: https://docs.rs/crate/quick-protobuf/0.8.1/source/src/reader.rs#443-462