Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

wbolster
Copy link
Contributor

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.

@wbolster wbolster requested a review from a team as a code owner July 21, 2022 08:54
@wbolster wbolster force-pushed the gh-95087-email-datetime-parsing branch from 262ef76 to cc496be Compare July 21, 2022 09:02
@serhiy-storchaka serhiy-storchaka self-requested a review July 21, 2022 18:41
@wbolster
Copy link
Contributor Author

note to reviewers, the problems is the [0] access after the previous line potentially reduced yy to an empty string:

        yy = yy[:-1]
    if not yy[0].isdigit():

Similar to bpo-45001 (pythonGH-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 pythongh-95087.
@wbolster wbolster force-pushed the gh-95087-email-datetime-parsing branch from cc496be to ee122d3 Compare July 22, 2022 19:27
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thank you for your PR. There are other similar bugs in this function, so I created #95201 to fix them all.

@@ -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())?

@corona10
Copy link
Member

close via #95201

@corona10 corona10 closed this Jul 30, 2022
@wbolster wbolster deleted the gh-95087-email-datetime-parsing branch October 4, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

email.utils.parsedate_tz() crashes on certain inputs
5 participants