diff options
-rw-r--r-- | autocrypt/src/lib.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs index 3c8c5cb0..aa82aed8 100644 --- a/autocrypt/src/lib.rs +++ b/autocrypt/src/lib.rs @@ -250,8 +250,9 @@ impl AutocryptHeaders { // // See https://tools.ietf.org/html/rfc5322#section-2.2.3 while let Some(Ok(nl)) = next_line { - if !nl.is_empty() && (&nl[0..1] == " " || &nl[0..1] == "\t") { - line.push_str(&nl[..]); + if !nl.is_empty() && (nl.starts_with(|c| c == ' ' || c == '\t')) + { + line.push_str(&nl); next_line = lines.next(); } else { // Put it back. @@ -1103,4 +1104,27 @@ mod test { &b"Testy McTestface <testy@example.org>"[..]); Ok(()) } + + /// Demonstrates a panic in the AutocryptHeader parser. + #[test] + fn issue_743() { + let data: Vec<u8> = vec![ + 0x41, 0x75, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x0a, 0xc4, + 0x83, 0x40, 0x39, 0x0a, 0x38, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, + 0x20, 0x74, 0x6f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x3a, 0x00, 0x00, + 0x0a, 0x0a, 0x0a, 0x0a, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x35, 0x39, 0x33, 0x35, 0x38, 0x36, 0x34, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x3e, 0x3f, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x3e, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x01, 0x08, 0x00, + 0x00, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x72, 0x79, 0x20, 0x02, 0x01, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x70, + ]; + let _ = AutocryptHeaders::from_bytes(&data); + } } |