php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60494 iconv_mime_decode does ignore special characters
Submitted: 2011-12-11 21:12 UTC Modified: 2018-11-13 22:31 UTC
From: bin at webcandy dot at Assigned: cmb (profile)
Status: Closed Package: ICONV related
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
 [2011-12-11 21:12 UTC] bin at webcandy dot at
Description:
------------
If the string $text passed to iconv_mime_decode($text) does contain special characters (tested with ä, ü and ß), it will just return an empty character for these characters.

In my opinion it iconv_mime_decode should leave special characters as they are as long as they're not encoded via Q-encoding.

Tested on Windows 7 and Debian.

iconv.output_encoding is set to "UTF-8"

Test script:
---------------
<?php

var_dump(iconv_mime_decode('ä'));
var_dump(iconv_mime_decode('ö'));
var_dump(iconv_mime_decode('ß'));

?>

Expected result:
----------------
string(1) "ä"
string(1) "ö"
string(1) "ß"

Actual result:
--------------
string(0) ""
string(0) ""
string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-11 21:16 UTC] bin at webcandy dot at
Expected result should probably have 2 bytes as I expect it to be UTF-8 when using iconv.output_encoding = UTF-8

Exptected result:
----------------
string(2) "ä"
string(2) "ö"
string(2) "ß"
 [2018-03-11 23:12 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-03-11 23:12 UTC] cmb@php.net
iconv_mime_decode() is supposed to decode a MIME header according
to RFC 2047. Neither 'ä', 'ö' nor 'ß' are valid characters in
headers, so returning these characters unmodified would be wrong.

However, it is not correct to simply skip invalid characters.
Instead the function should fail (i.e. return FALSE).  It seems
the problem is that inside of _php_iconv_mime_decode() all calls
to _php_iconv_appendc() ignore its return value (although all
calls to _php_iconv_appendl() cater to it).  In this case the
culprit is:
<https://github.com/php/php-src/blob/php-7.2.3/ext/iconv/iconv.c#L1538>
 [2018-08-25 15:38 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2018-08-25 15:54 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e29c946c29afdb0bf89c5329fcf3038448d50e17
Log: Fix #60494: iconv_mime_decode does ignore special characters
 [2018-08-25 15:54 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-11-13 22:17 UTC] shafer_w2002 at yahoo dot com
This fix has now broken all headers even with the ICONV_MIME_DECODE_CONTINUE_ON_ERROR flag set.   When this flag is set it should continue anyway.
 [2018-11-13 22:31 UTC] cmb@php.net
> This fix has now broken all headers even with the
> ICONV_MIME_DECODE_CONTINUE_ON_ERROR flag set.   When this flag is
> set it should continue anyway.

Thanks for reporting!  Tentatively, I agree with your statement.
However, since this fix has already been shipped with PHP 7.1.22
and 7.2.10, please open a new ticket (and assign to me, if
possible) to better be able to track the bug(fixe)s.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC