From efb86aef12ff4f8f3908ceff2844f7511f7d61eb Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 26 Aug 2018 12:59:17 +0200 Subject: Fix #68180: iconv_mime_decode can return extra characters in a header Basically, the algorithm to append a converted string to an existing `smart_str` works by increasing the `smart_str` buffer, to let `iconv` convert characters until there is no more space, to set the new length of the `smart_str` and to repeat until there is no more input. Formerly, the new length calculation has been wrong, though, since we would have to take the old `out_len` into account (`buf_growth - old_out_len - out_len`). However, since there is no need to take the old `out_len` into account when increasing the `smart_str` buffer, we can simplify the fix, avoiding an additional variable. --- NEWS | 2 ++ ext/iconv/iconv.c | 4 ++-- ext/iconv/tests/bug68180.phpt | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 ext/iconv/tests/bug68180.phpt diff --git a/NEWS b/NEWS index 08f0fae425..0f9806f13d 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ PHP NEWS . Fixed bug #76517 (incorrect restoring of LDFLAGS). (sji) - iconv: + . Fixed bug #68180 (iconv_mime_decode can return extra characters in a + header). (cmb) . Fixed bug #63839 (iconv_mime_decode_headers function is skipping headers). (cmb) . Fixed bug #60494 (iconv_mime_decode does ignore special characters). (cmb) diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index d759596d65..de5bccbb97 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -466,7 +466,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, if (in_p != NULL) { while (in_left > 0) { - out_left = buf_growth - out_left; + out_left = buf_growth; smart_str_alloc(d, out_left, 0); out_p = ZSTR_VAL((d)->s) + ZSTR_LEN((d)->s); @@ -500,7 +500,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, } } else { for (;;) { - out_left = buf_growth - out_left; + out_left = buf_growth; smart_str_alloc(d, out_left, 0); out_p = ZSTR_VAL((d)->s) + ZSTR_LEN((d)->s); diff --git a/ext/iconv/tests/bug68180.phpt b/ext/iconv/tests/bug68180.phpt new file mode 100644 index 0000000000..3442629235 --- /dev/null +++ b/ext/iconv/tests/bug68180.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #68180 (iconv_mime_decode can return extra characters in a header) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(183) "『【外資系戦略コンサルが集結】トップコンサルタントと話せるコンサル業界研究セミナー』へのエントリーありがとうございました。" +===DONE=== -- cgit v1.2.1