Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesbpo-36564: Fix infinite loop in email folding logic #12732
Conversation
This comment has been minimized.
This comment has been minimized.
I believe this will cause merge conflicts with #12020. I have subscribed to that PR and will rebase if it is merged first. |
chrome_len = len(encode_as) + 7 | ||
|
||
if (chrome_len + 1) >= maxlen: | ||
raise ValueError("Maximum length too short to fit any values") |
This comment has been minimized.
This comment has been minimized.
pganssle
Apr 8, 2019
Author
Member
I picked ValueError
here, but if there's a better error type let me know, I'm not super familiar with the email
module.
This comment has been minimized.
This comment has been minimized.
maxking
May 16, 2019
Contributor
We should probably use email.errors.HeaderParseError
instead of ValueError
.
It would be nice if you could use single quotes for consistency in the module.
Also, the error message seems a bit vague given that it is not too short to fit any value, but too short to hold encoded word. An ascii value would be just fine with the line length). And, Maximum length
is a hard to make sense when coming from an exception message. max_line_length
is more greppable to me.
What do you think about this error?
max_line_length is too small to fit an encoded word
.
This comment has been minimized.
This comment has been minimized.
warsaw
May 16, 2019
Member
+1 for HeaderParseError
but @bitdancer has more up-to-date perspective than I might have.
This comment has been minimized.
This comment has been minimized.
bitdancer
May 17, 2019
Member
No, a ValueError would be more appropriate here, I think, because it is an error in the value of maxlen. This isn't a parsing error, it's a rendering error.
Now, that said you might want to consider the fact that in _fold_mime_parameters
I deal with this issue by bumping maxlen to 78 rather than raising an error. I'm not sure that was the right choice, but whatever we do, it should probably be made consistent between the two cases. It is so sad that I never came back to fix that XXX comment I left myself :(
Note: I unfortunately am not too likely to see github comments, I get too much noise from that source...I just caught this one by chance. If you need my attention please post on the issue.
This comment has been minimized.
This comment has been minimized.
pganssle
May 17, 2019
Author
Member
Also, the error message seems a bit vague given that it is not too short to fit any value, but too short to hold encoded word. An ascii value would be just fine with the line length). And,
Maximum length
is a hard to make sense when coming from an exception message.max_line_length
is more greppable to me.
I agree that "Maximum length" is not going to be a good error, switching to max_line_length
is a good idea.
Regarding the "encoded word" situation, I guess when I wrote this I had assumed that the RFC chrome was added to every line regardless, but only realized that that wasn't the case through testing. I'm still not entirely clear why the encoding chrome is unnecessary for shorter words, but I think the suggested comments at least explain when the chrome becomes necessary.
This comment has been minimized.
This comment has been minimized.
chrome_len = len(encode_as) + 7 | ||
|
||
if (chrome_len + 1) >= maxlen: | ||
raise ValueError("Maximum length too short to fit any values") |
This comment has been minimized.
This comment has been minimized.
maxking
May 16, 2019
Contributor
We should probably use email.errors.HeaderParseError
instead of ValueError
.
It would be nice if you could use single quotes for consistency in the module.
Also, the error message seems a bit vague given that it is not too short to fit any value, but too short to hold encoded word. An ascii value would be just fine with the line length). And, Maximum length
is a hard to make sense when coming from an exception message. max_line_length
is more greppable to me.
What do you think about this error?
max_line_length is too small to fit an encoded word
.
# required length for a line | ||
|
||
# Note: This is only triggered when there is a single word longer than | ||
# maxlen, hence the 1234567890 at the end of this whimsical subject |
This comment has been minimized.
This comment has been minimized.
maxking
May 16, 2019
Contributor
Slight change to the comment to make it a bit more clear why this bug is trigerred when there is a single world longer than maxlen
.
# Note: This is only triggered when there is a single word longer than
# max_line_length. This is because when we encounter a word longer than max_line_length,
# it is broken down into encoded words to fit max_line_length. If the max_line_length isn't
# large enough to even contain RFC 2047 chrome (`?=<charset>?q??=`), we fail.
# Hence the 1234567890 at the end of this whimsical subject.
Just to make it clear that Header can have words longer than max line length, as long as max_line_length > 7 + len(charset) + 1
.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
warsaw
May 16, 2019
Member
HeaderParseError
seems right to me too, but maybe @bitdancer has a different opinion?
This comment has been minimized.
This comment has been minimized.
msapiro
May 16, 2019
Actually, the phrase "even contain RFC 2047 chrome (?=<charset>?q??=
)" should probably be "even contain RFC 2047 chrome plus one character(?=<charset>?q?x?=
)"
def test_short_maxlen_error(self): | ||
# RFC 2047 chrome takes up 7 characters, plus the length of the charset | ||
# name, so folding should fail if maxlen is lower than the minimum | ||
# required length for a line |
This comment has been minimized.
This comment has been minimized.
See inlined comments. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
May 16, 2019
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
This comment has been minimized.
This comment has been minimized.
msapiro
commented
May 16, 2019
This comment has been minimized.
This comment has been minimized.
Also @pganssle you may want to change the description, since the first point (The value being folded contains a single word (no spaces) longer than max_line_length) isn't true. |
This comment has been minimized.
This comment has been minimized.
Thanks for the reviews everyone. Just as an update, I am planning on making the requested changes soon, but I've just started a new job and I'm still working out some of the IP issues so I've been holding off on any non-trivial OSS work until that's sorted out. Shouldn't be too much longer. |
184072d
to
aff66ad
This comment has been minimized.
This comment has been minimized.
I have made the requested changes; please review again |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jul 14, 2019
Thanks for making the requested changes! @warsaw: please review the changes made to this pull request. |
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
This comment has been minimized.
This comment has been minimized.
LGTM! @pganssle It is usually better to not force push and just keep adding more commits as your make changes your existing PR. It makes it a bit easy to remember what changes were made after the previous review, especially if it has been a while since last review :) |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jul 16, 2019
When you're done making the requested changes, leave the comment: |
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Jul 16, 2019
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jul 16, 2019
GH-14797 is a backport of this pull request to the 3.8 branch. |
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jul 16, 2019
GH-14798 is a backport of this pull request to the 3.7 branch. |
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jul 16, 2019
GH-14799 is a backport of this pull request to the 3.6 branch. |
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564 (cherry picked from commit f69d5c6) Co-authored-by: Paul Ganssle <pganssle@users.noreply.github.com>
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
As far as I can tell, this infinite loop would be triggered if: 1. The value being folded contains a single word (no spaces) longer than max_line_length 2. The max_line_length is shorter than the encoding's name + 9 characters. bpo-36564: https://bugs.python.org/issue36564
pganssle commentedApr 8, 2019
•
edited by bedevere-bot
As far as I can tell, this infinite loop would be triggered if:
max_line_length
characters.
bpo-36564: https://bugs.python.org/issue36564
https://bugs.python.org/issue36564