Browse Source

Fix OOB-panic with invalid binary coded data

master
Graham Northup 3 months ago
parent
commit
49c6a65301
  1. 3
      src/coding.rs
  2. 1
      src/error.rs

3
src/coding.rs

@ -46,6 +46,9 @@ impl CodedObject {
pub fn from_binary(bytes: &[u8]) -> error::Result<CodedObject> {
let scheme_len = bytes[0];
if scheme_len >= bytes.len() {
return Err(Error::InvalidSchemeLength(scheme_len));
}
let scheme = std::str::from_utf8(&bytes[1 .. scheme_len as usize + 1])?;
Ok(CodedObject {
scheme: scheme.into(),

1
src/error.rs

@ -2,6 +2,7 @@
pub enum Error {
CodingError(base64::DecodeError),
InvalidLength(usize),
InvalidSchemeLength(u8),
BadScheme(String),
BadEncoding(std::str::Utf8Error),
SchemeTooLong(std::num::TryFromIntError),

Loading…
Cancel
Save