From 06d309fd7a917575d65c7a6f4f57b0e6bb0f9711 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sun, 22 Apr 2018 21:26:06 -0700 Subject: Fix bug #76249 - fail on invalid sequences --- ext/iconv/iconv.c | 3 +++ ext/iconv/tests/bug76249.phpt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 ext/iconv/tests/bug76249.phpt diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 69dd8c1cf7..fca5331541 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -2672,6 +2672,9 @@ static int php_iconv_stream_filter_append_bucket( tcnt = 0; break; } + } else { + php_error_docref(NULL, E_WARNING, "iconv stream filter (\"%s\"=>\"%s\"): invalid multibyte sequence", self->from_charset, self->to_charset); + goto out_failure; } break; diff --git a/ext/iconv/tests/bug76249.phpt b/ext/iconv/tests/bug76249.phpt new file mode 100644 index 0000000000..5a9d8f171e --- /dev/null +++ b/ext/iconv/tests/bug76249.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequence) +--SKIPIF-- + +--FILE-- + +DONE +--EXPECTF-- +Warning: stream_get_contents(): iconv stream filter ("ucs-2"=>"utf8//IGNORE"): invalid multibyte sequence in %sbug76249.php on line %d +慢DONE -- cgit v1.2.1 From 8dca5ae5ece54dde2e303df26fe291282a342798 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sun, 22 Apr 2018 22:19:51 -0700 Subject: Fix test --- ext/iconv/tests/bug76249.phpt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/iconv/tests/bug76249.phpt b/ext/iconv/tests/bug76249.phpt index 5a9d8f171e..1503f0bc81 100644 --- a/ext/iconv/tests/bug76249.phpt +++ b/ext/iconv/tests/bug76249.phpt @@ -8,9 +8,11 @@ $fh = fopen('php://memory', 'rw'); fwrite($fh, "abc"); rewind($fh); stream_filter_append($fh, 'convert.iconv.ucs-2/utf8//IGNORE', STREAM_FILTER_READ, []); -echo stream_get_contents($fh); +$a = stream_get_contents($fh); +var_dump(strlen($a)); ?> DONE --EXPECTF-- Warning: stream_get_contents(): iconv stream filter ("ucs-2"=>"utf8//IGNORE"): invalid multibyte sequence in %sbug76249.php on line %d -慢DONE +int(3) +DONE -- cgit v1.2.1