From c3d6730e9cc1362bd4810b5d828fd3a3fa2c9ddc Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 18 Aug 2024 20:42:20 +0000 Subject: [PATCH] #45: Fix index issue --- src/lib.rs | 4 +++- src/tests/fuzzing.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 723148d..8a9e717 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1132,7 +1132,9 @@ impl Parser { } if idx + 3 < len_l && &tokens[idx + 3] == sep { - if let Some(value) = info.month_index(&tokens[idx + 4]) { + if tokens.len() <= idx + 4 { + return Err(ParseError::UnrecognizedFormat); + } else if let Some(value) = info.month_index(&tokens[idx + 4]) { ymd.append(value as i32, &tokens[idx + 4], Some(YMDLabel::Month))?; } else if let Ok(val) = tokens[idx + 4].parse::() { ymd.append(val, &tokens[idx + 4], None)?; diff --git a/src/tests/fuzzing.rs b/src/tests/fuzzing.rs index 55befea..2e7400b 100644 --- a/src/tests/fuzzing.rs +++ b/src/tests/fuzzing.rs @@ -96,4 +96,11 @@ fn github_36() { let parse_str = str::from_utf8(&parse_vec).unwrap(); let parse_result = parse(parse_str); assert!(parse_result.is_err()); +} + +#[test] +fn github_45() { + assert!(parse("/2018-fifa-").is_err()); + assert!(parse("/2009/07/").is_err()); + assert!(parse("2021-09-").is_err()); } \ No newline at end of file