[PHP-BUG] Bug #43314 [Com]: iconv_mime_encode(), broken Q scheme
Edit report at http://bugs.php.net/bug.php?id=43314&edit=1 ID: 43314 Comment by: Reported by: wiela at centras dot lt Summary: iconv_mime_encode(), broken Q scheme Status: No Feedback Type: Bug Package: ICONV related Operating System: Windows XP HE PHP Version: 5.2.5 New Comment: Why has the status been set to No Feedback? Is this going to be fixed? Previous Comments: [2009-11-28 22:18:35] dennispopel at gmail dot com Same on Vista/PHP5.3.0 [2009-01-09 14:38:50] om at viazenetti dot de Hm, is this bugged fixed in newer versions? Currently we are using version 5.2.6 and the error still occures. [2008-11-04 01:00:01] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". [2008-10-27 12:56:37] j...@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://windows.php.net/snapshots/ [2008-02-01 14:10:33] d_kelsey at uk dot ibm dot com I encountered a similar problem with another utf-8 string, and although this may not be the best way to fix it, this change provides a workaround. in iconv.c (line 1281 in php5.2.5) the line out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / (3 - 1); should be changed to out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3; It looks like the code attempts to determine how many characters would fit into output buffer when converted (given that it has gone over the limit), but it assumes that on average each character uses 2 bytes (ie an even mixture of encoded and printable characters). A lot of strings will be greater than this and out_size will be set to a very large positive number (as it subtracts a larger number from out_size and being unsigned will result in a large positive number). The workaround is to take the worst case scenario and assume all characters generated 3 bytes (ie all encoded). 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 http://bugs.php.net/bug.php?id=43314 -- Edit this bug report at http://bugs.php.net/bug.php?id=43314&edit=1
#43314 [Com]: iconv_mime_encode(), broken Q scheme
ID: 43314 Comment by: dennispopel at gmail dot com Reported By: wiela at centras dot lt Status: No Feedback Bug Type: ICONV related Operating System: Windows XP HE PHP Version: 5.2.5 New Comment: Same on Vista/PHP5.3.0 Previous Comments: [2009-01-09 14:38:50] om at viazenetti dot de Hm, is this bugged fixed in newer versions? Currently we are using version 5.2.6 and the error still occures. [2008-11-04 01:00:01] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". [2008-10-27 12:56:37] j...@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://windows.php.net/snapshots/ [2008-02-01 14:10:33] d_kelsey at uk dot ibm dot com I encountered a similar problem with another utf-8 string, and although this may not be the best way to fix it, this change provides a workaround. in iconv.c (line 1281 in php5.2.5) the line out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / (3 - 1); should be changed to out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3; It looks like the code attempts to determine how many characters would fit into output buffer when converted (given that it has gone over the limit), but it assumes that on average each character uses 2 bytes (ie an even mixture of encoded and printable characters). A lot of strings will be greater than this and out_size will be set to a very large positive number (as it subtracts a larger number from out_size and being unsigned will result in a large positive number). The workaround is to take the worst case scenario and assume all characters generated 3 bytes (ie all encoded). [2007-11-16 16:23:17] wiela at centras dot lt Description: iconv_mime_encode(),'Q' encoding scheme isn't reliable and sometimes (for particular character and/or string length combination?) returns: "Notice: iconv_mime_encode(): Unknown error (7) in ..." *without any result*. This also applies to earlier php versions (tested with php 5.2.1). Reproduce code: --- $preferences = array( "input-charset" => "UTF-8", "output-charset" => "UTF-8", "line-length" => 76, "line-break-chars" => "\n", "scheme" => "Q" ); // $str1 results error, it's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFs8Wr' $str1 = "ąčęėįų įęčųęįą čęųąųū"; // $str2 doesn't result error, although it's only one character // shorter. It's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFsw==' $str2 = "ąčęėįų įęčųęįą čęųąų"; echo iconv_mime_encode("Subject", $str1, $preferences); echo iconv_mime_encode("Subject", $str2, $preferences); Expected result: Well, at least any (*some*) result is expected, without any errors and warnings. For $str1 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3=C5=AB?= For $str2 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= Actual result: -- For $str1: FALSE with "Notice: iconv_mime_encode(): Unknown error (7) in ..." For $str2: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= -- Edit this bug report at http://bugs.php.net/?id=43314&edit=1
#43314 [Com]: iconv_mime_encode(), broken Q scheme
ID: 43314 Comment by: om at viazenetti dot de Reported By: wiela at centras dot lt Status: No Feedback Bug Type: ICONV related Operating System: Windows XP HE PHP Version: 5.2.5 New Comment: Hm, is this bugged fixed in newer versions? Currently we are using version 5.2.6 and the error still occures. Previous Comments: [2008-11-04 01:00:01] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". [2008-10-27 12:56:37] j...@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://windows.php.net/snapshots/ [2008-02-01 14:10:33] d_kelsey at uk dot ibm dot com I encountered a similar problem with another utf-8 string, and although this may not be the best way to fix it, this change provides a workaround. in iconv.c (line 1281 in php5.2.5) the line out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / (3 - 1); should be changed to out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3; It looks like the code attempts to determine how many characters would fit into output buffer when converted (given that it has gone over the limit), but it assumes that on average each character uses 2 bytes (ie an even mixture of encoded and printable characters). A lot of strings will be greater than this and out_size will be set to a very large positive number (as it subtracts a larger number from out_size and being unsigned will result in a large positive number). The workaround is to take the worst case scenario and assume all characters generated 3 bytes (ie all encoded). [2007-11-16 16:23:17] wiela at centras dot lt Description: iconv_mime_encode(),'Q' encoding scheme isn't reliable and sometimes (for particular character and/or string length combination?) returns: "Notice: iconv_mime_encode(): Unknown error (7) in ..." *without any result*. This also applies to earlier php versions (tested with php 5.2.1). Reproduce code: --- $preferences = array( "input-charset" => "UTF-8", "output-charset" => "UTF-8", "line-length" => 76, "line-break-chars" => "\n", "scheme" => "Q" ); // $str1 results error, it's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFs8Wr' $str1 = "ąčęėįų įęčųęįą čęųąųū"; // $str2 doesn't result error, although it's only one character // shorter. It's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFsw==' $str2 = "ąčęėįų įęčųęįą čęųąų"; echo iconv_mime_encode("Subject", $str1, $preferences); echo iconv_mime_encode("Subject", $str2, $preferences); Expected result: Well, at least any (*some*) result is expected, without any errors and warnings. For $str1 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3=C5=AB?= For $str2 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= Actual result: -- For $str1: FALSE with "Notice: iconv_mime_encode(): Unknown error (7) in ..." For $str2: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= -- Edit this bug report at http://bugs.php.net/?id=43314&edit=1
#43314 [Com]: iconv_mime_encode(), broken Q scheme
ID: 43314 Comment by: d_kelsey at uk dot ibm dot com Reported By: wiela at centras dot lt Status: Open Bug Type: ICONV related Operating System: Windows XP HE PHP Version: 5.2.5 New Comment: I encountered a similar problem with another utf-8 string, and although this may not be the best way to fix it, this change provides a workaround. in iconv.c (line 1281 in php5.2.5) the line out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / (3 - 1); should be changed to out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3; It looks like the code attempts to determine how many characters would fit into output buffer when converted (given that it has gone over the limit), but it assumes that on average each character uses 2 bytes (ie an even mixture of encoded and printable characters). A lot of strings will be greater than this and out_size will be set to a very large positive number (as it subtracts a larger number from out_size and being unsigned will result in a large positive number). The workaround is to take the worst case scenario and assume all characters generated 3 bytes (ie all encoded). Previous Comments: [2007-11-16 16:23:17] wiela at centras dot lt Description: iconv_mime_encode(),'Q' encoding scheme isn't reliable and sometimes (for particular character and/or string length combination?) returns: "Notice: iconv_mime_encode(): Unknown error (7) in ..." *without any result*. This also applies to earlier php versions (tested with php 5.2.1). Reproduce code: --- $preferences = array( "input-charset" => "UTF-8", "output-charset" => "UTF-8", "line-length" => 76, "line-break-chars" => "\n", "scheme" => "Q" ); // $str1 results error, it's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFs8Wr' $str1 = "ąčęėįų įęčųęįą čęųąųū"; // $str2 doesn't result error, although it's only one character // shorter. It's utf-8 string, its base64_encode() is: //'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFsw==' $str2 = "ąčęėįų įęčųęįą čęųąų"; echo iconv_mime_encode("Subject", $str1, $preferences); echo iconv_mime_encode("Subject", $str2, $preferences); Expected result: Well, at least any (*some*) result is expected, without any errors and warnings. For $str1 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3=C5=AB?= For $str2 is expected: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= Actual result: -- For $str1: FALSE with "Notice: iconv_mime_encode(): Unknown error (7) in ..." For $str2: Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?= =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?= =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?= -- Edit this bug report at http://bugs.php.net/?id=43314&edit=1