Bug #53891 [Ver]: iconv_mime_encode() fails to Q-encode UTF-8 string

From: Date: Sun, 12 Aug 2018 13:25:55 +0000
Subject: Bug #53891 [Ver]: iconv_mime_encode() fails to Q-encode UTF-8 string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216734@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53891&edit=1

 ID:                 53891
 Updated by:         cmb@php.net
 Reported by:        can at strg dot at
-Summary:            iconv_mime_encode() fails converting UTF-8 string to
                     quoted-printable
+Summary:            iconv_mime_encode() fails to Q-encode UTF-8 string
 Status:             Verified
 Type:               Bug
 Package:            ICONV related
 Operating System:   GNU/linux (gentoo/kernel 2.6.35)
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

<https://github.com/php/php-src/pull/3436> is
supposed to resolve
this issue.


Previous Comments:
------------------------------------------------------------------------
[2017-12-06 08:30:34] af at ins dot de

Sorry. ZendFramework-version is obviouisly not 5.6.32, it is: 2.4.13

------------------------------------------------------------------------
[2017-12-06 08:27:28] af at ins dot de

We have encountered the same bug when encoding UTF-8 strings with PHP 5.6.32 and PHP 7.1.7. A fix
after this long time would be really nice.

As a sidenote: This error impacts also the ZendFramework (5.6.32) because Zend/Mail;Zend/Header is
checking with iconv_mime_encode() if a subject line is valid and throws a "Subject value must
be composed of printable US-ASCII or UTF-8 characters" instead of sending the mail when the bug
occurs.

------------------------------------------------------------------------
[2016-08-13 11:12:32] cmb@php.net

Only changing the threshold does not work, unfortunately.

------------------------------------------------------------------------
[2015-09-09 22:18:18] cmb@php.net

The culprit is the check whether there is sufficient place in the
line to add another encoded word[1]. out_charset_len + 12 is not
sufficient for quoted-printable encoding of UTF-8. In the worst
case it is out_charset_len + BOILERPLATE + CHARS_PER_BYTE *
MAX_BYTES (where BOILERPLATE == 7, CHARS_PER_BYTE == 3 and
MAX_BYTES == 6), i.e. out_charset_len + 25.

AFAIK, this would be sufficient for all other character encodings
and for Base64 encoding as well. Of course, changing this
threshold might change the result of iconv_mime_encode with regard
to folding, but that supposedly would only break some tests, if
they're relying on the exact output. It would more severly affect
any code that uses small line-length values, but presumably such
code doesn't exist – actually, I can't see a reason to set
line-length < 76.

[1] <https://github.com/php/php-src/blob/php-7.0.0RC2/ext/iconv/iconv.c#L1238>

------------------------------------------------------------------------
[2015-09-09 18:09:21] cmb@php.net

Confirmed: <https://3v4l.org/JLman>

Error 7 is likely E2BIG, what occurs if there's not enough room at
*outbuf when calling iconv().

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=53891


--
Edit this bug report at https://bugs.php.net/bug.php?id=53891&edit=1


Thread (7 messages)

« previous php.bugs (#216734) next »