ID: 50954 Updated by: j...@php.net Reported By: hiroaki dot kawai at gmail dot com -Status: Open +Status: Bogus Bug Type: ICONV related PHP Version: 5.2.12 New Comment:
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. See bug #48289 Previous Comments: ------------------------------------------------------------------------ [2010-02-07 14:15:50] hiroaki dot kawai at gmail dot com Description: ------------ iconv_mime_encode fails Q-encoding when encoding non-ascii chars, which case is very common. This problem does not happen if line-length is long enough to hold the encoded string in a single line. The code use unsigned int to capture expected byte. In Q-encoding, the value is goes to negative value (at iconv.c line 1295), and fails separating the value into multiple lines. Patch as following: =============================== --- iconv.c.orig 2008-12-31 20:17:49.000000000 +0900 +++ iconv.c 2010-02-07 11:01:54.436000000 +0900 @@ -1217,7 +1217,7 @@ prev_in_left = ini_in_left = in_left; ini_in_p = in_p; - for (out_size = char_cnt; out_size > 0;) { + for (out_size = (char_cnt-2)/3; out_size > 0;) { size_t prev_out_left; nbytes_required = 0; Reproduce code: --------------- <?php ini_set('error_reporting',E_ALL); echo iconv_mime_encode('a',"\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88",array('output-charset'=>'UTF-8','input-charset'=>'UTF-8','scheme'=>'Q','line-length'=>30)); Expected result: ---------------- a: =?UTF-8?Q?=E3=83=86?= =?UTF-8?Q?=E3=82=B9?= =?UTF-8?Q?=E3=83=88?= =?UTF-8?Q?=E3=83=86?= =?UTF-8?Q?=E3=82=B9?= =?UTF-8?Q?=E3=83=88?= Actual result: -------------- Notice: iconv_mime_encode(): Unknown error (7) in /home/hawk/hoge.php on line 3 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50954&edit=1