Skip to content

Conversation

@cmb69
Copy link
Member

@cmb69 cmb69 commented Sep 4, 2018

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

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>
@cmb69
Copy link
Member Author

cmb69 commented Sep 4, 2018

@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).

@cmb69
Copy link
Member Author

cmb69 commented Sep 4, 2018

The test failure is unrelated to this patch.

@cmb69
Copy link
Member Author

cmb69 commented Sep 15, 2018

With this further insight, the fix for bug 53891 should be reinvestigated.

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).

@php-pulls
Copy link

Comment on behalf of cmb at php.net:

Applied via 9cbe128.

@php-pulls php-pulls closed this Sep 22, 2018
@cmb69 cmb69 deleted the fix-66828 branch September 22, 2018 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants