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`.
This commit is contained in:
Christoph M. Becker 2018-08-12 19:55:09 +02:00
parent b9bf9ddce6
commit 6e1980e152
3 changed files with 42 additions and 0 deletions

3
NEWS
View File

@ -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)

View File

@ -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;

View File

@ -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===