-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-105802: email._header_value_parser: prevent IndexError in get_obs_local_part #108133
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
Conversation
FWIW this fixed my local breakage with offlineimap and certain mails from microsoft:
and it has not broken anything else in my current usage |
'<', # sic | ||
'<', # sic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do these "sic" mean?
Also, reformat slightly to make the indentation more obvious
Lib/email/_header_value_parser.py
Outdated
or (obs_local_part[0].token_type=='cfws' | ||
and len(obs_local_part) == 1 | ||
or obs_local_part[1].token_type=='dot')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for all these new cases. For example this condition is passed if there are more that 1 parts and the second part is a dot. Does it report a defect "Invalid leading '.' in local part" for "python.org"?
@fsc-eriker, please sign the CLA; without that, we cannot merge the PR. |
…ingle cwf Don't add new error cases when refactoring; simply ensure that the code avoids an IndexError for the cases it attempts to handle
The CLA was already signed (see edit history of @cpython-cla-bot's post), the issue with it now came from the history getting twisted up somehow. I'll see if I can straighten it out, but the PR may be tainted to the point of needing to be remade. |
bac1f84
to
03efb0d
Compare
@fsc-eriker, I force-pushed to your branch to clean up the history, removing what looks like a rebase misfire. Please do If this is still pinging everyone that was brought in by the old history, it may be better to go ahead and recreate this PR anyway :) |
@zware Sorry for botching the rebase and thanks for fixing it. The reason I attempted a rebase is that Github remarks that my branch is out of date with respect to |
Yeah, you can ignore that (unless there's something important you need from All PRs are squashed to a single commit on merge, and rebases can make it harder to review new changes. |
If you create a branch from up-to-date local main, then as soon as a merge to cpython/main happens, which is multiple times a day, it is out of date. If you update your branch with `git merge upstream/main' (the usual right way) and immediately push to your fork and create a PR, it will soon be out-of-date. This is routine. Only worry if it says there is a merge conflict. Almost never use rebase as it is easy to create problems and almost never needed. A coredev looking to merge who notices that a PR is way out-of-date but still able to be merged may update the branch to rerun tests to make sure they still pass. This depends on what the patch does and how likely other changes could be a problem. |
Thank you for your contribution, @fsc-eriker, but I think that it is not a correct solution. Invalid Message-ID should not be truncated, even with adding defects. The parsing code should raise HeaderParseError, this will allow to preserve its literal value. See #117934. |
Since the initial version of your PR also raised an exception, I added you as the co-author of #117934. |
The parsing logic is supposed to raise an error if the header cannot be parsed, but I found a corner case where this didn't happen, and a different error ended up being raised, which caused Python to abort for some malformed messages.
Pardon any problems with this PR; this is my first one.
I have completed the CLA in 2021 (BPO user name eriker)