Browse Source

melib: fix out-of-bounds parser bug

tags/alpha-0.4.1
Manos Pitsidianakis 2 years ago
parent
commit
3dfb2f4f2c
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 3
      melib/src/email/compose.rs
  2. 7
      melib/src/email/parser.rs
  3. 4
      testing/src/email_parse.rs

3
melib/src/email/compose.rs

@ -416,7 +416,7 @@ mod tests {
#[test]
fn test_attachments() {
return;
/*
let mut default = Draft::default();
default.set_body("αδφαφσαφασ".to_string());
@ -434,6 +434,7 @@ mod tests {
.set_content_transfer_encoding(ContentTransferEncoding::Base64);
default.attachments_mut().push(attachment);
println!("{}", default.finalise().unwrap());
*/
}
}

7
melib/src/email/parser.rs

@ -488,8 +488,13 @@ fn display_addr(input: &[u8]) -> IResult<&[u8], Address> {
length: end,
}
};
let rest_start = if input.len() > end + display_name.length + 2 {
end + display_name.length + 3
} else {
end + display_name.length + 2
};
IResult::Done(
&input[end + display_name.length + 3..],
&input[rest_start..],
Address::Mailbox(MailboxAddress {
raw,
display_name,

4
testing/src/email_parse.rs

@ -14,8 +14,8 @@ fn main() -> Result<()> {
filename.display()
));
let env = Envelope::from_bytes(&buffer.as_bytes(), None).expect("Couldn't parse email");
debug!("Env is {:#?}", env);
debug!(env.body_bytes(buffer.as_bytes()));
eprintln!("Env is {:#?}", env);
eprintln!("{:?}", env.body_bytes(buffer.as_bytes()));
} else {
println!("it's not a file");
}

Loading…
Cancel
Save