diff --git a/src/lib.rs b/src/lib.rs index 7b226f4..b894482 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -746,11 +746,11 @@ impl Parser { // Jan-01[-99] let sep = &l[i + 1]; // TODO: This seems like a very unsafe unwrap - ymd.append(l[i + 2].parse::().unwrap(), &l[i + 2], None)?; + ymd.append(l[i + 2].parse::()?, &l[i + 2], None)?; if i + 3 < len_l && &l[i + 3] == sep { // Jan-01-99 - ymd.append(l[i + 4].parse::().unwrap(), &l[i + 4], None)?; + ymd.append(l[i + 4].parse::()?, &l[i + 4], None)?; i += 2; } @@ -813,17 +813,17 @@ impl Parser { // TODO: check that l[i + 1] is integer? if len_li == 4 { // -0300 - hour_offset = Some(l[i + 1][..2].parse::().unwrap()); - min_offset = Some(l[i + 1][2..4].parse::().unwrap()); + hour_offset = Some(l[i + 1][..2].parse::()?); + min_offset = Some(l[i + 1][2..4].parse::()?); } else if i + 2 < len_l && l[i + 2] == ":" { // -03:00 - hour_offset = Some(l[i + 1].parse::().unwrap()); - min_offset = Some(l[i + 3].parse::().unwrap()); + hour_offset = Some(l[i + 1].parse::()?); + min_offset = Some(l[i + 3].parse::()?); i += 2; } else if len_li <= 2 { // -[0]3 let range_len = min(l[i + 1].len(), 2); - hour_offset = Some(l[i + 1][..range_len].parse::().unwrap()); + hour_offset = Some(l[i + 1][..range_len].parse::()?); min_offset = Some(0); } @@ -1027,9 +1027,9 @@ impl Parser { let s = &tokens[idx]; if ymd.len() == 0 && tokens[idx].find('.') == None { - ymd.append(s[0..2].parse::().unwrap(), &s[0..2], None)?; - ymd.append(s[2..4].parse::().unwrap(), &s[2..4], None)?; - ymd.append(s[4..6].parse::().unwrap(), &s[4..6], None)?; + ymd.append(s[0..2].parse::()?, &s[0..2], None)?; + ymd.append(s[2..4].parse::()?, &s[2..4], None)?; + ymd.append(s[4..6].parse::()?, &s[4..6], None)?; } else { // 19990101T235959[.59] res.hour = s[0..2].parse::().ok(); @@ -1043,12 +1043,12 @@ impl Parser { // YYMMDD let s = &tokens[idx]; ymd.append( - s[..4].parse::().unwrap(), + s[..4].parse::()?, &s[..4], Some(YMDLabel::Year), )?; - ymd.append(s[4..6].parse::().unwrap(), &s[4..6], None)?; - ymd.append(s[6..8].parse::().unwrap(), &s[6..8], None)?; + ymd.append(s[4..6].parse::()?, &s[4..6], None)?; + ymd.append(s[6..8].parse::()?, &s[6..8], None)?; if len_li > 8 { res.hour = Some(s[8..10].parse::()?); @@ -1090,7 +1090,7 @@ impl Parser { { // TODO: There's got to be a better way of handling the condition above let sep = &tokens[idx + 1]; - ymd.append(value_repr.parse::().unwrap(), &value_repr, None)?; + ymd.append(value_repr.parse::()?, &value_repr, None)?; if idx + 2 < len_l && !info.jump_index(&tokens[idx + 2]) { if let Ok(val) = tokens[idx + 2].parse::() { diff --git a/src/tests/fuzzing.rs b/src/tests/fuzzing.rs index d9ca04c..e0695c5 100644 --- a/src/tests/fuzzing.rs +++ b/src/tests/fuzzing.rs @@ -40,3 +40,10 @@ fn test_fuzz() { Err(ParseError::ImpossibleTimestamp("Invalid minute")) ); } + +#[test] +fn large_int() { + let parse_result = parse("1412409095009.jpg"); + assert!(parse_result.is_err()); + println!("{:?}", parse_result); +} \ No newline at end of file