summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2018-09-22 15:30:08 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2018-09-22 15:31:02 +0200
commit7c2cc9aa56efb3f990967aee2fc0569df19a4d50 (patch)
treefced93b42c0f431f1d5163b1ebe9bb17d37a01f2
parentc26902911fbb0ba2121ff4b5fd23159cf9c14115 (diff)
parent9cbe1283f70699b82ca4225705d40fcc73633dfb (diff)
downloadphp-git-7c2cc9aa56efb3f990967aee2fc0569df19a4d50.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix #66828: iconv_mime_encode Q-encoding longer than it should be
-rw-r--r--NEWS4
-rw-r--r--ext/iconv/iconv.c4
-rw-r--r--ext/iconv/tests/bug66828.phpt21
3 files changed, 27 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index d2acdd1b90..7690f0e454 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ PHP NEWS
. Fixed bug #76480 (Use curl_multi_wait() so that timeouts are respected).
(Pierrick)
+- iconv:
+ . Fixed bug #66828 (iconv_mime_encode Q-encoding longer than it should be).
+ (cmb)
+
- Opcache:
. Fixed bug #76832 (ZendOPcache.MemoryBase periodically deleted by the OS).
(Anatol)
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 9a3c2d02fd..19df4e0179 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -1358,7 +1358,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
prev_in_left = ini_in_left = in_left;
ini_in_p = in_p;
- for (out_size = (char_cnt - 2) / 3; out_size > 0;) {
+ for (out_size = (char_cnt - 2); out_size > 0;) {
#if !ICONV_SUPPORTS_ERRNO
size_t prev_out_left;
#endif
@@ -1422,7 +1422,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
break;
}
- out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3;
+ out_size -= ((nbytes_required - (char_cnt - 2)) + 2) / 3;
in_left = ini_in_left;
in_p = ini_in_p;
}
diff --git a/ext/iconv/tests/bug66828.phpt b/ext/iconv/tests/bug66828.phpt
new file mode 100644
index 0000000000..9914b41b14
--- /dev/null
+++ b/ext/iconv/tests/bug66828.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #66828 (iconv_mime_encode Q-encoding longer than it should be)
+--SKIPIF--
+<?php
+if (!extension_loaded('iconv')) die('skip iconv extension not available');
+?>
+--FILE--
+<?php
+$preferences = array(
+ "input-charset" => "ISO-8859-1",
+ "output-charset" => "UTF-8",
+ "line-length" => 76,
+ "line-break-chars" => "\n",
+ "scheme" => "Q"
+);
+var_dump(iconv_mime_encode("Subject", "Test Test Test Test Test Test Test Test", $preferences));
+?>
+===DONE===
+--EXPECT--
+string(74) "Subject: =?UTF-8?Q?Test=20Test=20Test=20Test=20Test=20Test=20Test=20Test?="
+===DONE===