Repository navigation
gh-151857: Fix IndexError in the email header parser on empty input - #151858
Open
tonghuaroot wants to merge 3 commits into
Open
tonghuaroot wants to merge 3 commits into
tonghuaroot wants to merge 3 commits into
Conversation
…nput Guard two empty-input index escapes in the modern email header parser that raised a bare IndexError instead of a parse defect: a MIME parameter name ending with '*', and an address display name that is only a comment.
|
This PR is stale because it has been open for 90 days with no activity. |
…arser Value.stripped_value indexed an empty Value built by get_parameter's quoted extended-value recovery, so name*="'" raised IndexError. Return early for an empty value.
Contributor
Author
|
the description said the fuzz found no other exception escaping the parser. that was wrong, it missed a third case of the same bug. an empty quoted rfc 2231 extended value, for example name*="'" or name*="us-ascii''", builds an empty Value in get_parameter, and Value.stripped_value then raises IndexError from message_from_string(). the new commit makes stripped_value return early for an empty value, so the parameter gets an empty value plus the existing InvalidHeaderDefect. it adds tests for both layers, and i updated the news entry, the description and the issue to cover the three cases. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three cases where the email header parser lets a bare
IndexErrorescape on malformed input instead of recording a defect:get_parameter: a parameter name ending in*with no value leavesvalueempty beforevalue[0].DisplayName.display_name: a display name that is only a comment emptiesresafterres.pop(0), thenres[-1]raises.Value.stripped_value: an empty quoted RFC 2231 extended value (name*="'",name*="us-ascii''") builds an emptyValue, thenself[0]raises.Each now degrades to the existing recovery path. Calling the low-level
get_*token parsers directly with an empty string still raises, but every caller checks for that first.Tests cover each case at the parser level (
test__header_value_parser.py) and through the header API (test_headerregistry.py).