diff options
author | Kartikaya Gupta <kats@trevize.staktrace.com> | 2019-07-31 21:50:25 -0400 |
---|---|---|
committer | Kartikaya Gupta <kats@trevize.staktrace.com> | 2019-07-31 21:50:25 -0400 |
commit | 1eebb00ac2b318cc897183a0a31018efbed449fd (patch) | |
tree | f0b04ab699117369e8bba3a23699752d2a8d00b7 | |
parent | 0b7386914341559700ef53735cbd6aabfa240e29 (diff) |
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.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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); + } + } + } } |