summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKartikaya Gupta <kats@trevize.staktrace.com>2019-08-05 07:30:52 -0400
committerKartikaya Gupta <kats@trevize.staktrace.com>2019-08-05 07:31:57 -0400
commit7522e5fbbb1c7bd870473196593d56d513786787 (patch)
tree1704065ed60b37190b0ba9a75b71391b0c6c64b1
parentf01f80d5fd6da9003254aea85d5825e9b6f90356 (diff)
downloadmailparse-7522e5fbbb1c7bd870473196593d56d513786787.tar.gz
mailparse-7522e5fbbb1c7bd870473196593d56d513786787.tar.xz
Prevent possible underflow
Fixes #43
-rw-r--r--src/lib.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 87bac95..e6999ad 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -108,6 +108,9 @@ fn find_from(line: &str, ix_start: usize, key: &str) -> Option<usize> {
fn find_from_u8(line: &[u8], ix_start: usize, key: &[u8]) -> Option<usize> {
assert!(!key.is_empty());
assert!(ix_start < line.len());
+ if line.len() < key.len() {
+ return None;
+ }
let ix_end = line.len() - key.len();
if ix_start <= ix_end {
for i in ix_start..ix_end {
@@ -1430,4 +1433,14 @@ mod tests {
}
}
}
+
+ #[test]
+ fn test_fuzzer_testcase_2() {
+ const INPUT: &'static str = "U3ViamVjdDogVGhpcyBpcyBhIHRlc3QgZW1haWwKQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PczMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMZm9vYmFyCkRhdGU6IFN1biwgMDIgT2MKCi1TdWJqZWMtZm9vYmFydDo=";
+ if let Ok(parsed) = parse_mail(&base64::decode(INPUT).unwrap()) {
+ if let Ok(Some(date)) = parsed.headers.get_first_value("Date") {
+ let _ = dateparse(&date);
+ }
+ }
+ }
}