8000 gh-95087: make email date parsing more robust by wbolster · Pull Request #95089 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-95087: make email date parsing more robust #95089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-95087: make email date parsing more robust
Similar to bpo-45001 (GH-89164), this makes email date parsing more
robust against malformed input. parsedate_tz() is supposed to return
None for malformed input, but could crash on certain inputs, e.g.

    >>> email.utils.parsedate_tz('17 June , 2022')
    IndexError: string index out of range

Fixes gh-95087.
  • Loading branch information
wbolster committed Jul 22, 2022
commit ee122d37e6d638bb521c868f7e2e447244bb2f73
2 changes: 1 addition & 1 deletion Lib/email/_parseaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _parsedate_tz(data):
yy, tm = tm, yy
if yy[-1] == ',':
yy = yy[:-1]
if not yy[0].isdigit():
if yy and not yy[0].isdigit():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if not (yy and yy[0].isdigit())?

yy, tz = tz, yy
if tm[-1] == ',':
tm = tm[:-1]
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,7 @@ def test_parsedate_returns_None_for_invalid_strings(self):
self.assertIsNone(utils.parsedate_tz(' '))
self.assertIsNone(utils.parsedate('0'))
self.assertIsNone(utils.parsedate_tz('0'))
self.assertIsNone(utils.parsedate_tz('17 June , 2022'))
self.assertIsNone(utils.parsedate('A Complete Waste of Time'))
self.assertIsNone(utils.parsedate_tz('A Complete Waste of Time'))
self.assertIsNone(utils.parsedate_tz('Wed, 3 Apr 2002 12.34.56.78+0800'))
Expand Down
0