Skip to content

Commit

Permalink
Fix GH-7980: Unexpected result for iconv_mime_decode
Browse files Browse the repository at this point in the history
We need to reset the shift state right after conversion, to cater to
potenially following plain encodings.  Also, there is no need to reset
the shift for plain encodings, because these are not state-dependent.

Closes GH-8025.
  • Loading branch information
cmb69 committed Feb 7, 2022
1 parent bea542a commit 86c196b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PHP NEWS

- Iconv:
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
. Fixed bug GH-7980 (Unexpected result for iconv_mime_decode). (cmb)

- Zlib:
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
Expand Down
10 changes: 3 additions & 7 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
}

err = _php_iconv_appendl(pretval, ZSTR_VAL(decoded_text), ZSTR_LEN(decoded_text), cd);
if (err == PHP_ICONV_ERR_SUCCESS) {
err = _php_iconv_appendl(pretval, NULL, 0, cd);
}
zend_string_release_ex(decoded_text, 0);

if (err != PHP_ICONV_ERR_SUCCESS) {
Expand Down Expand Up @@ -1716,13 +1719,6 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
*next_pos = p1;
}

if (cd != (iconv_t)(-1)) {
_php_iconv_appendl(pretval, NULL, 0, cd);
}
if (cd_pl != (iconv_t)(-1)) {
_php_iconv_appendl(pretval, NULL, 0, cd_pl);
}

smart_str_0(pretval);
out:
if (cd != (iconv_t)(-1)) {
Expand Down
13 changes: 13 additions & 0 deletions ext/iconv/tests/gh7980.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Bug GH-7980 (Unexpected result for iconv_mime_decode)
--SKIPIF--
<?php
if (!extension_loaded("iconv")) die("skip iconv extension not available");
?>
--FILE--
<?php
$subject = '=?windows-1258?Q?DSI_Charg=E9_de_Formation_Jean_Dupont?= <jdupont@example.fr>';
var_dump(iconv_mime_decode($subject, ICONV_MIME_DECODE_STRICT, 'UTF-8'));
?>
--EXPECT--
string(57) "DSI Chargé de Formation Jean Dupont <jdupont@example.fr>"

0 comments on commit 86c196b

Please sign in to comment.