summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-08-12 19:55:09 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-08-25 14:40:07 +0200
commit6e1980e1520306cc5ec7109ccb3d7c8a0a672689 (patch)
tree9b2953dc687aa1f5238bf81911265cbaac8c7509
parentb9bf9ddce6b0813df60b346fca7919735f158cd5 (diff)
downloadphp-git-6e1980e1520306cc5ec7109ccb3d7c8a0a672689.tar.gz
Fix #55146: iconv_mime_decode_headers() skips some headers
If we're expecting the start of an encoded word (`=?`), but instead of the question mark get a line break (CR or LF), we must not append it to the `pretval`.
-rw-r--r--NEWS3
-rw-r--r--ext/iconv/iconv.c3
-rw-r--r--ext/iconv/tests/bug55146.phpt36
3 files changed, 42 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 727508aac5..e3bf418fce 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ PHP NEWS
- gettext:
. Fixed bug #76517 (incorrect restoring of LDFLAGS). (sji)
+- iconv:
+ . Fixed bug #55146 (iconv_mime_decode_headers() skips some headers). (cmb)
+
- intl:
. Fixed bug #74484 (MessageFormatter::formatMessage memory corruption with
11+ named placeholders). (Anatol)
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 7f7125b09f..a76b6fd802 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -1555,6 +1555,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
case 1: /* expecting a delimiter */
if (*p1 != '?') {
+ if (*p1 == '\r' || *p1 == '\n') {
+ --p1;
+ }
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl);
if (err != PHP_ICONV_ERR_SUCCESS) {
goto out;
diff --git a/ext/iconv/tests/bug55146.phpt b/ext/iconv/tests/bug55146.phpt
new file mode 100644
index 0000000000..b3c2015314
--- /dev/null
+++ b/ext/iconv/tests/bug55146.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Bug #55146 (iconv_mime_decode_headers() skips some headers)
+--SKIPIF--
+<?php
+if (!extension_loaded('iconv')) die('skip iconv extension not available');
+?>
+--FILE--
+<?php
+
+$headers = <<< HEADERS
+X-Header-One: H4sIAAAAAAAAA+NgFlsCAAA=
+X-Header-Two: XtLePq6GTMn8G68F0
+HEADERS;
+var_dump(iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR));
+
+$headers = <<< HEADERS
+X-Header-One: =
+X-Header-Two: XtLePq6GTMn8G68F0
+HEADERS;
+var_dump(iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_STRICT));
+?>
+===DONE===
+--EXPECT--
+array(2) {
+ ["X-Header-One"]=>
+ string(24) "H4sIAAAAAAAAA+NgFlsCAAA="
+ ["X-Header-Two"]=>
+ string(17) "XtLePq6GTMn8G68F0"
+}
+array(2) {
+ ["X-Header-One"]=>
+ string(1) "="
+ ["X-Header-Two"]=>
+ string(17) "XtLePq6GTMn8G68F0"
+}
+===DONE===