From b905fda07dc1b01c4b2f855d3c2f6086e0c10ed8 Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Sun, 10 May 2026 11:15:48 +0200 Subject: [PATCH] Reject dates with invalid month names --- CHANGELOG.md | 4 ++++ resources/date.json | 28 +++++++++++++++++----------- src/parsers/fields/date.rs | 14 +++++++++----- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef33ab..7137b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +mail-parser 0.11.4 +================================ +- Reject dates with invalid month names. + mail-parser 0.11.3 ================================ - Fix panic with messages containing corrupted attachments (#145) diff --git a/resources/date.json b/resources/date.json index 6da01fd..147736e 100644 --- a/resources/date.json +++ b/resources/date.json @@ -359,17 +359,7 @@ }, { "header": "13 zzz 2021 09:55:06 +0200", - "expected": { - "year": 2021, - "month": 0, - "day": 13, - "hour": 9, - "minute": 55, - "second": 6, - "tz_before_gmt": false, - "tz_hour": 2, - "tz_minute": 0 - } + "expected": null }, { "header": "by 2002:aa7:cd10:0:b0:45c:2c83:1208 with SMTP id b16-20020aa7cd10000000b0045c2c831208mr4220805edw.81.1665423075119;\n\tMon, 10 Oct 2022 10:31:15 -0700 (PDT)", @@ -440,5 +430,21 @@ "tz_hour": 0, "tz_minute": 0 } + }, + { + "header": "Tue, 7 All 2026 19:14:51 +0000", + "expected": null + }, + { + "header": "Tue, 7 Bog 2026 19:14:51 +0000", + "expected": null + }, + { + "header": "Tue, 7 Sjj 2026 19:14:51 +0000", + "expected": null + }, + { + "header": "Tue, 7 00 2026 19:14:51 +0000", + "expected": null } ] \ No newline at end of file diff --git a/src/parsers/fields/date.rs b/src/parsers/fields/date.rs index 1c780e4..6e357d9 100644 --- a/src/parsers/fields/date.rs +++ b/src/parsers/fields/date.rs @@ -412,6 +412,14 @@ impl<'x> MessageStream<'x> { } if pos >= 6 { + let month: u8 = if month_pos == 3 { + MONTH_MAP.get(month_hash).copied().unwrap_or(0) + } else { + parts[1] as u8 + }; + if !(1..=12).contains(&month) { + return HeaderValue::Empty; + } HeaderValue::DateTime(DateTime { year: if (0..=49).contains(&parts[2]) { parts[2] + 2000 @@ -420,11 +428,7 @@ impl<'x> MessageStream<'x> { } else { parts[2] } as u16, - month: if month_pos == 3 && month_hash <= 30 { - MONTH_MAP[month_hash] - } else { - parts[1] as u8 - }, + month, day: parts[0] as u8, hour: parts[3] as u8, minute: parts[4] as u8,