php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48289 iconv_mime_encode() quoted-printable scheme is broken
Submitted: 2009-05-15 03:29 UTC Modified: 2010-05-04 13:57 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: astax dot t at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: ICONV related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2009-05-15 03:29 UTC] astax dot t at gmail dot com
Description:
------------
When used with "Q" scheme, iconv_mime_encode produces wrong results, crashes of hangs. I suspect this happens with long (though not VERY long) strings.

Lines are not correctly wrapped with "line-break-chars" parameter.


In reproduce code note missing linebreaks in encoded string and duplicated second word in decoded string.

Reproduce code:
---------------
// Content below is in Windows-1251 charset
$str = '?????? "???????-?????????" ??? "?????????" ??? ???????????';

$par = array(
	'scheme' => 'Q',
	'input-charset' => 'CP1251',
	'output-charset' => 'CP1251',
	'line-length' => 74,
);

$res = iconv_mime_encode('Subject', $str, $par);
echo $res."\n";
$res = iconv_mime_decode($res, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'CP1251');
echo $res."\n";



=================================================================
Second example:

$str = '???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ????';

$par = array(
	'scheme' => 'Q',
	'input-charset' => 'CP1251',
	'output-charset' => 'CP1251',
);

$res = iconv_mime_encode('Subject', $str, $par);
echo $res."\n";


Expected result:
----------------
Subject: =?CP1251?Q?=D4=E8=EB=E8?==?CP1251?Q?=E0=EB=20?==?CP1251?Q?"?=           =?CP1251?Q?=C7=E0=EF=E0=E4=ED=EE-=D1=E8=E1=E8=F0=F1=EA=E8=E9"=20=CE=C0=CE?=     =?CP1251?Q?=20"=D1=EE=E1=E8=ED=E1=E0=ED=EA"=20=F0=E0=E4=20=EF=F0?=              =?CP1251?Q?=E5=E4=F1=F2=E0=E2=E8=F2=FC?=                                       Subject: ?????? "???????-?????????" ??? "?????????" ??? ???????????


=================================================================
Second example:

expected encoded string to be displayed

Actual result:
--------------
Subject: =?CP1251?Q?=D4=E8=EB=E8?==?CP1251?Q?=E0=EB=20?==?CP1251?Q?"=C7=E0=EF=E0=E4=ED?==?CP1251?Q?"=C7=E0=EF=E0=E4=ED=EE-=D1=E8=E1=E8=F0=F1=EA=E8=E9"=20=CE=C0=CE=20"=D1=EE=E1=E8=ED=E1=E0=ED=EA"=20=F0=E0=E4=20=EF=F0=E5=E4=F1=F2=E0=E2=E8=F2=FC?=
Subject: ?????? "??????"???????-?????????" ??? "?????????" ??? ???????????


=================================================================
Second example:

PHP hangs

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-16 17:45 UTC] dypa at bk dot ru
all tests give error:
Notice: iconv_mime_encode() [function.iconv-mime-encode]: Unknown error (7) in /var/www/def.php on line 12

user@localhost:/rss$ php -v
PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 23 2009 14:35:05) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

iconv
iconv support 	enabled 
iconv implementation 	glibc 
iconv library version 	2.9
 [2009-07-10 03:02 UTC] astax dot t at gmail dot com
dypa at bk dot ru: Please make sure you use Windows-1251 charset everywhere when you copy and paste test content. Everywhere means in browser and in text editor.
In your case I think iconv fails because you pasted the text in ISO-8859-1 charset.
 [2009-10-13 08:22 UTC] rosier at interstroom dot nl
// PHP version: 5.3.0
echo 'PHP version: ' . phpversion();

$subject = base64_decode('VEVTVCDigJMg0KMg0L3QsNGBINC10YHRgtGMINGC0L4sINGH0YLQviDQktCw0Lwg0L3Rg9C20L3QviAtIFRFU1Q=');

$preferences = array(
    'line-length' => 500,
    'input-charset' => 'UTF-8',
    'output-charset' => 'UTF-8',
    'scheme' => 'Q'
);
$result = iconv_mime_encode('Subject', $subject, $preferences);
// OK: $result = string
var_dump($result);

$preferences = array(
    'line-length' => 76,
    'input-charset' => 'UTF-8',
    'output-charset' => 'UTF-8',
    'scheme' => 'Q'
);
$result = iconv_mime_encode('Subject', $subject, $preferences);
// WRONG: $result = FALSE
var_dump($result);
 [2010-02-07 17:38 UTC] jani@php.net
See also bug #50954 (has a patch too)
 [2010-02-08 03:55 UTC] astax dot t at gmail dot com
I'd like to test the patch described in #50954. Is it included into any PHP build already? Sorry, I don't feel like compiling PHP from sources.


Here is one more reproduce code:

$str = base64_decode("1Ojr6ODrICLH4O/g5O3uLdHo4ejw8ero6SIgzsDOICLR7uHo7eHg7eoiIPDg5CDv8OXk8fLg4ujy/A==");

$par = array(
	'scheme' => 'Q',
	'input-charset' => 'CP1251',
	'output-charset' => 'CP1251',
	'line-length' => 74,
);

$res = iconv_mime_encode('Subject', $str, $par);

$res = iconv_mime_decode($res, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'CP1251');
echo 'Result: Length='.strlen($res)."  ".$res."\n";
$expected = "Subject: ".$str;
echo 'Expected: Length='.strlen($expected)."  ".$expected."\n";



It says result length is 74 chars and expected is 67.
 [2010-05-04 13:52 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2010-05-04 13:57 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=298963
Log: Fix for bug #48289 (iconv_mime_encode() quoted-printable scheme is broken).
Thanks to Hiroaki Kawai for the original patch.
 [2010-05-04 13:57 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-05-04 13:57 UTC] aharvey@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-06-14 07:19 UTC] jinhuakehao at hotmail dot com
this is great help to design new bug to any backdoors, thanks so much, it's Love 
from http://www.favordeal.com
 [2012-09-04 06:05 UTC] sunfeng891031 at gmail dot com
thanks!it's useful for me !
i used them in my website:
http://www.dualshine.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC