Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Commit81148c6
Various date parsing utilities in the email module, such asemail.utils.parsedate(), are supposed to gracefully handle invalidinput, typically by raising an appropriate exception or by returningNone.The internal email._parseaddr._parsedate_tz() helper used by some ofthese date parsing routines tries to be robust against malformed input,but unfortunately it can still crash ungracefully when a non-empty butwhitespace-only input is passed. This manifests as an unexpectedIndexError.In practice, this can happen when parsing an email with only a newlineinside a ‘Date:’ header, which unfortunately happens occasionally in thereal world.Here's a minimal example: $ python Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import email.utils >>> email.utils.parsedate('foo') >>> email.utils.parsedate(' ') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.9/email/_parseaddr.py", line 176, in parsedate t = parsedate_tz(data) File "/usr/lib/python3.9/email/_parseaddr.py", line 50, in parsedate_tz res = _parsedate_tz(data) File "/usr/lib/python3.9/email/_parseaddr.py", line 72, in _parsedate_tz if data[0].endswith(',') or data[0].lower() in _daynames: IndexError: list index out of rangeThe fix is rather straight-forward: guard against empty lists, aftersplitting on whitespace, but before accessing the first element.(cherry picked from commit989f6a3)Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee>
1 parent6ebfe8d commit81148c6
File tree
3 files changed
+6
-0
lines changed- Lib
- email
- test/test_email
- Misc/NEWS.d/next/Library
3 files changed
+6
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3002 | 3002 | | |
3003 | 3003 | | |
3004 | 3004 | | |
| 3005 | + | |
| 3006 | + | |
3005 | 3007 | | |
3006 | 3008 | | |
3007 | 3009 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments
Comments
(0)