diff --git a/src/de.rs b/src/de.rs index 170e0593..610cd46d 100644 --- a/src/de.rs +++ b/src/de.rs @@ -327,15 +327,10 @@ where } } - fn convert_str<'a>(buf: &'a [u8], buf_end_offset: u64) -> Result<&'a str> { - match str::from_utf8(buf) { - Ok(s) => Ok(s), - Err(e) => { - let shift = buf.len() - e.valid_up_to(); - let offset = buf_end_offset - shift as u64; - Err(Error::syntax(ErrorCode::InvalidUtf8, offset)) - } - } + fn convert_str<'a>(buf: &'a [u8], _buf_end_offset: u64) -> Result<&'a str> { + // ! This is unsafe, but guaranteed not to be used in the Filecoin protocol, outside of + // ! the one usage this is required for. + Ok(unsafe { str::from_utf8_unchecked(buf) }) } fn parse_str(&mut self, len: usize, visitor: V) -> Result