Skip to content

Commit 150e2b8

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #66828: iconv_mime_encode Q-encoding longer than it should be
2 parents 9f3aac9 + 7c2cc9a commit 150e2b8

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug #76901 (method_exists on SPL iterator passthrough method corrupts
1515
memory). (Nikita)
1616

17+
- iconv:
18+
. Fixed bug #66828 (iconv_mime_encode Q-encoding longer than it should be).
19+
(cmb)
20+
1721
- Opcache:
1822
. Fixed bug #76711 (OPcache enabled triggers false-positive "Illegal string
1923
offset"). (Dmitry)

ext/iconv/iconv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
13571357
prev_in_left = ini_in_left = in_left;
13581358
ini_in_p = in_p;
13591359

1360-
for (out_size = (char_cnt - 2) / 3; out_size > 0;) {
1360+
for (out_size = (char_cnt - 2); out_size > 0;) {
13611361
#if !ICONV_SUPPORTS_ERRNO
13621362
size_t prev_out_left;
13631363
#endif
@@ -1421,7 +1421,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
14211421
break;
14221422
}
14231423

1424-
out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3;
1424+
out_size -= ((nbytes_required - (char_cnt - 2)) + 2) / 3;
14251425
in_left = ini_in_left;
14261426
in_p = ini_in_p;
14271427
}

ext/iconv/tests/bug53891.phpt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ Bug #53891 (iconv_mime_encode() fails to Q-encode UTF-8 string)
55
if (!extension_loaded('iconv')) die('skip iconv extension not available');
66
?>
77
--FILE--
8-
<?php
9-
$preferences = array(
10-
'scheme' => 'Q',
11-
'input-charset' => 'utf-8',
12-
'output-charset' => 'utf-8',
13-
'line-length' => 74,
14-
'line-break-chars' => "\r\n",
15-
);
16-
var_dump(iconv_mime_encode('subject', "d obeybiubrsfqllpdtpge…", $preferences));
8+
<?php
9+
$preferences = array(
10+
'scheme' => 'Q',
11+
'input-charset' => 'utf-8',
12+
'output-charset' => 'utf-8',
13+
'line-length' => 74,
14+
'line-break-chars' => "\r\n",
15+
);
16+
var_dump(iconv_mime_encode('subject', "d obeybiubrsfqllpdtpge…", $preferences));
1717
?>
1818
===DONE===
1919
--EXPECT--
20-
string(81) "subject: =?utf-8?Q?d=20obeybiubrsfqllp?==?utf-8?Q?dtpge?=
21-
=?utf-8?Q?=E2=80=A6?="
20+
string(54) "subject: =?utf-8?Q?d=20obeybiubrsfqllpdtpge=E2=80=A6?="
2221
===DONE===

ext/iconv/tests/bug66828.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #66828 (iconv_mime_encode Q-encoding longer than it should be)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('iconv')) die('skip iconv extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$preferences = array(
10+
"input-charset" => "ISO-8859-1",
11+
"output-charset" => "UTF-8",
12+
"line-length" => 76,
13+
"line-break-chars" => "\n",
14+
"scheme" => "Q"
15+
);
16+
var_dump(iconv_mime_encode("Subject", "Test Test Test Test Test Test Test Test", $preferences));
17+
?>
18+
===DONE===
19+
--EXPECT--
20+
string(74) "Subject: =?UTF-8?Q?Test=20Test=20Test=20Test=20Test=20Test=20Test=20Test?="
21+
===DONE===

0 commit comments

Comments
 (0)