From 6e1980e1520306cc5ec7109ccb3d7c8a0a672689 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 12 Aug 2018 19:55:09 +0200 Subject: 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`. --- NEWS | 3 +++ ext/iconv/iconv.c | 3 +++ ext/iconv/tests/bug55146.phpt | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 ext/iconv/tests/bug55146.phpt 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-- + +--FILE-- + +===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=== -- cgit v1.2.1