]> granicus.if.org Git - php/commitdiff
Fix #77147: Fix for 60494 ignores ICONV_MIME_DECODE_CONTINUE_ON_ERROR
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 14 Nov 2018 13:55:38 +0000 (14:55 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 14 Nov 2018 13:55:38 +0000 (14:55 +0100)
If the `ICONV_MIME_DECODE_CONTINUE_ON_ERROR` flag is set, parsing
should not fail, if there are illegal characters in the headers;
instead we silently ignore these like before.

NEWS
ext/iconv/iconv.c
ext/iconv/tests/bug77147.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f6ae98fe7bf9d1a55a86e52bebd5aaad888d8da6..dbb7c1fff92c628aa9701485abac7b35f7d6a4db 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2018, PHP 7.1.25
 
+- iconv:
+  . Fixed bug #77147 (Fixing 60494 ignored ICONV_MIME_DECODE_CONTINUE_ON_ERROR).
+    (cmb)
+
 - ODBC:
   . Fixed bug #77079 (odbc_fetch_object has incorrect type signature).
     (Jon Allen)
index ef27b20645be0321aff03bb2b96ca348638b7cea..f86d0ae031987a12d45b9c10efc255f58262966b 100644 (file)
@@ -1546,7 +1546,11 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
                                        default: /* first letter of a non-encoded word */
                                                err = _php_iconv_appendc(pretval, *p1, cd_pl);
                                                if (err != PHP_ICONV_ERR_SUCCESS) {
-                                                       goto out;
+                                                       if (mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR) {
+                                                               err = PHP_ICONV_ERR_SUCCESS;
+                                                       } else {
+                                                               goto out;
+                                                       }
                                                }
                                                encoded_word = NULL;
                                                if ((mode & PHP_ICONV_MIME_DECODE_STRICT)) {
diff --git a/ext/iconv/tests/bug77147.phpt b/ext/iconv/tests/bug77147.phpt
new file mode 100644 (file)
index 0000000..839f897
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Bug #77147 (Fixing 60494 ignored ICONV_MIME_DECODE_CONTINUE_ON_ERROR)
+--SKIPIF--
+<?php
+if (!extension_loaded('iconv')) die('skip iconv extension not available');
+?>
+--FILE--
+<?php
+$string = <<<EOF
+Feedback-ID: 014a93e3-1f5e-4df6-b347-6b59f0f746b8:b5891053-55d1-45bc-a0b5-47a7a9b59687:email:epslh1�
+EOF;
+$headers = iconv_mime_decode_headers($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
+var_dump($headers);
+?>
+===DONE===
+--EXPECT--
+array(1) {
+  ["Feedback-ID"]=>
+  string(86) "014a93e3-1f5e-4df6-b347-6b59f0f746b8:b5891053-55d1-45bc-a0b5-47a7a9b59687:email:epslh1"
+}
+===DONE===