From:             hiroaki dot kawai at gmail dot com
Operating system: 
PHP version:      5.2.12
PHP Bug Type:     ICONV related
Bug description:  iconv_mime_encode fails in Q-encoding

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 bug report at http://bugs.php.net/?id=50954&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50954&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50954&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50954&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50954&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50954&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50954&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50954&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50954&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50954&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50954&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50954&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50954&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50954&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50954&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50954&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50954&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50954&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50954&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50954&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50954&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50954&r=mysqlcfg

Reply via email to