summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKartikaya Gupta <kats@trevize.staktrace.com>2019-07-31 21:50:25 -0400
committerKartikaya Gupta <kats@trevize.staktrace.com>2019-07-31 21:50:25 -0400
commit1eebb00ac2b318cc897183a0a31018efbed449fd (patch)
treef0b04ab699117369e8bba3a23699752d2a8d00b7
parent0b7386914341559700ef53735cbd6aabfa240e29 (diff)
downloadmailparse-1eebb00ac2b318cc897183a0a31018efbed449fd.tar.gz
mailparse-1eebb00ac2b318cc897183a0a31018efbed449fd.tar.xz
Skip past unterminated =? escape string
This fixes a panic where we stupidly advance our byte index by 2 when encountering an unterminated escape. Doing this is inefficient because we'll probably just find the same unterminated escape a bunch of times, but can also put our byte index in the middle of a UTF-8 character which causes a panic. Fixes #41
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7af26bc..87bac95 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -229,6 +229,7 @@ impl<'a> MailHeader<'a> {
}
None => {
result.push_str(&"=?");
+ ix_search = ix_begin - 2;
}
};
break;
@@ -1418,4 +1419,15 @@ mod tests {
_ => assert!(false),
};
}
+
+ #[test]
+ fn test_fuzzer_testcase() {
+ const INPUT: &'static str = "U3ViamVjdDplcy1UeXBlOiBtdW50ZW50LVV5cGU6IW11bAAAAAAAAAAAamVjdDplcy1UeXBlOiBtdW50ZW50LVV5cGU6IG11bAAAAAAAAAAAAAAAAABTTUFZdWJqZf86OiP/dCBTdWJqZWN0Ol8KRGF0ZTog/////////////////////wAAAAAAAAAAAHQgYnJmAHQgYnJmZXItRW5jeXBlOnY9NmU3OjA2OgAAAAAAAAAAAAAAADEAAAAAAP/8mAAAAAAAAAAA+f///wAAAAAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAPT0/PzEAAAEAAA==";
+
+ if let Ok(parsed) = parse_mail(&base64::decode(INPUT).unwrap()) {
+ if let Ok(Some(date)) = parsed.headers.get_first_value("Date") {
+ let _ = dateparse(&date);
+ }
+ }
+ }
}