You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some invalid email address groups cause an IndexError instead of a HeaderParseError #76359
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-08-11.21:09:42.939>created_at=<Date2017-11-30.10:40:34.903>labels= ['3.8', 'type-bug', '3.7', 'expert-email', '3.9']
title='Some invalid email address groups cause an IndexError instead of a HeaderParseError'updated_at=<Date2019-08-11.21:09:42.931>user='https://github.com/mtorromeo'
In case an address email header contains and empty string, the tokenizer return a BareQuotedString
which is also a TokenList, but this list is empty and the parser fails to check this and insteads raises an IndexError.
For example an email with this header will trigger the IndexError:
ReplyTo: ""
mtorromeo commented on Nov 30, 2017
mtorromeomannequin
MannequinAuthor
More actions
Disregard my last message, I posted it in the wrong bug report by mistake.
Sorry about the noise
The fact that the original report mentions HeaderParserError implies that the new API is being used, though the report didn't make that clear. The problem still exists:
>>> m = message_from_string("To: :Foo <foo@example.com> <bar@example.com>\n\n", policy=default)
>>> m['To']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rdmurray/python/p38/Lib/email/message.py", line 391, in __getitem__
return self.get(name)
File "/home/rdmurray/python/p38/Lib/email/message.py", line 471, in get
return self.policy.header_fetch_parse(k, v)
File "/home/rdmurray/python/p38/Lib/email/policy.py", line 163, in header_fetch_parse
return self.header_factory(name, value)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 602, in __call__
return self[name](name, value)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 197, in __new__
cls.parse(value, kwds)
File "/home/rdmurray/python/p38/Lib/email/headerregistry.py", line 343, in parse
groups.append(Group(addr.display_name,
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 315, in display_name
return self[0].display_name
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 382, in display_name
return self[0].display_name
File "/home/rdmurray/python/p38/Lib/email/_header_value_parser.py", line 564, in display_name
if res[0].token_type == 'cfws':
IndexError: list index out of range
New changeset 09a1872 by Miss Islington (bot) (Abhilash Raj) in branch 'master': bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044) 09a1872
New changeset 9500bbe by Miss Islington (bot) in branch '3.8': bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044) 9500bbe
New changeset dec231a by Miss Islington (bot) in branch '3.7': bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044) dec231a
Activity
mtorromeo commentedon Nov 30, 2017
With some malformed email address list, the parser for email groups raises an
IndexErrorinstead of the correctHeaderParseError.This results in a complete failure to parse the email while it is still preferable to just ignore the malformed header.
An example of such a malformed list is this:
To: :Foo <foo@example.com> <bar@example.com>mtorromeo commentedon Nov 30, 2017
In case an address email header contains and empty string, the tokenizer return a BareQuotedString
which is also a TokenList, but this list is empty and the parser fails to check this and insteads raises an IndexError.
For example an email with this header will trigger the IndexError:
ReplyTo: ""
mtorromeo commentedon Nov 30, 2017
Disregard my last message, I posted it in the wrong bug report by mistake.
Sorry about the noise
maxking commentedon Jun 14, 2019
I don't think this is an issue anymore, I guess this was fixed as a part of some other PR.
I tested this out on a recent branch:
>>> import email >>> msg = email.message_from_string('From: Abhilash <maxking@email.com> <Another@some.com>') >>> msg['From'] 'Abhilash <maxking@email.com> <Another@some.com>'@david, @barry: I think we can close this issue.
csabella commentedon Jul 3, 2019
Based on @maxking's comment, I'm going to close this issue. Thank you!
bitdancer commentedon Jul 10, 2019
The fact that the original report mentions HeaderParserError implies that the new API is being used, though the report didn't make that clear. The problem still exists:
miss-islington commentedon Aug 11, 2019
New changeset 09a1872 by Miss Islington (bot) (Abhilash Raj) in branch 'master':
bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044)
09a1872
miss-islington commentedon Aug 11, 2019
New changeset 9500bbe by Miss Islington (bot) in branch '3.8':
bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044)
9500bbe
miss-islington commentedon Aug 11, 2019
New changeset dec231a by Miss Islington (bot) in branch '3.7':
bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044)
dec231a