Skip to content

Commit

Permalink
Allow unsafe utf8 string deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell committed Oct 14, 2020
1 parent a218403 commit 3e7bf81
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V>(&mut self, len: usize, visitor: V) -> Result<V::Value>
Expand Down

0 comments on commit 3e7bf81

Please sign in to comment.