From 3d5de7d74660b1ba6ae92a91581f7a50573554dc Mon Sep 17 00:00:00 2001 From: XXiang Date: Sat, 4 Jul 2020 22:12:57 +0800 Subject: Fix bug #79787 Closes GH-5807. --- NEWS | 3 +++ ext/mbstring/libmbfl/mbfl/mbfilter.c | 14 +++++++++----- ext/mbstring/tests/bug79787.phpt | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 ext/mbstring/tests/bug79787.phpt diff --git a/NEWS b/NEWS index 17289b59e0..071e456a88 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,9 @@ PHP NEWS - FTP: . Fixed bug #55857 (ftp_size on large files). (cmb) +- Mbstring: + . Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang) + - Standard: . Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb) diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 313ea598fc..fdbbb9d2a9 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -1734,13 +1734,17 @@ mbfl_strimwidth( mbfl_convert_filter_flush(encoder); if (pc.status != 0 && mkwidth > 0) { pc.width += mkwidth; - while (n > 0) { - if ((*encoder->filter_function)(*p++, encoder) < 0) { - break; + if (n > 0) { + while (n > 0) { + if ((*encoder->filter_function)(*p++, encoder) < 0) { + break; + } + n--; } - n--; + mbfl_convert_filter_flush(encoder); + } else if (pc.outwidth > pc.width) { + pc.status++; } - mbfl_convert_filter_flush(encoder); if (pc.status != 1) { pc.status = 10; pc.device.pos = pc.endpos; diff --git a/ext/mbstring/tests/bug79787.phpt b/ext/mbstring/tests/bug79787.phpt new file mode 100644 index 0000000000..c53c3b67f3 --- /dev/null +++ b/ext/mbstring/tests/bug79787.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #79787 mb_strimwidth does not trim string +--SKIPIF-- + +--FILE-- + +--EXPECT-- +一. +一二. +一二三 +abc. +abcd. +abcdef -- cgit v1.2.1