Fix #66828: iconv_mime_encode Q-encoding longer than it should be#3492
Closed
cmb69 wants to merge 1 commit intophp:PHP-7.1from
Closed
Fix #66828: iconv_mime_encode Q-encoding longer than it should be#3492cmb69 wants to merge 1 commit intophp:PHP-7.1from
cmb69 wants to merge 1 commit intophp:PHP-7.1from
Conversation
Before the fix for bug 48289 has been applied, the algorithm to construct a Q-encoded-word has been optimistic, i.e. try to encode as many bytes that *may* fit in the remaining space, calculate the actual length of the Q-encoded word, and if it's too long, try again with a reduced size. However, the fix for the mentioned bug replaced this by a pessimistic algorithm, which always terminates[1] the for loop[2] during the first iteration (which renders the following 3 lines as dead code), and as such easily produces unnecessarily short encoded-words. Instead the proper fix for the bug would have been to make sure that `out_size` is always decremented, if the space isn't sufficient for the encoded-word. With this further insight, the fix for bug 53891 should be reinvestigated. [1] <https://github.com/php/php-src/blob/php-7.3.0beta3/ext/iconv/iconv.c#L1421> [2] <https://github.com/php/php-src/blob/php-7.3.0beta3/ext/iconv/iconv.c#L1360>
Member
Author
|
@LawnGnome @moriyoshi Since you've fixed bug #48289 back then, could you please review this PR? Note to potential merger: the expectation of bug53891.phpt has to be adjusted to this patch (PHP-7.3+ only). |
Member
Author
|
The test failure is unrelated to this patch. |
Member
Author
I've just did, and that bugfix is necessary in addition to this PR. Anyhow, unless there are objections, I'm going to merge this PR on next weekend (i.e. in a week). |
|
Comment on behalf of cmb at php.net: Applied via 9cbe128. |
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.
Before the fix for bug 48289 has been applied, the algorithm to
construct a Q-encoded-word has been optimistic, i.e. try to encode as
many bytes that may fit in the remaining space, calculate the actual
length of the Q-encoded word, and if it's too long, try again with a
reduced size. However, the fix for the mentioned bug replaced this by
a pessimistic algorithm, which always terminates[1] the for loop[2]
during the first iteration (which renders the following 3 lines as dead
code), and as such easily produces unnecessarily short encoded-words.
Instead the proper fix for the bug would have been to make sure that
out_sizeis always decremented, if the space isn't sufficient for theencoded-word.
With this further insight, the fix for bug 53891 should be
reinvestigated.
[1] https://github.com/php/php-src/blob/php-7.3.0beta3/ext/iconv/iconv.c#L1421
[2] https://github.com/php/php-src/blob/php-7.3.0beta3/ext/iconv/iconv.c#L1360