Skip to content

Instantly share code, notes, and snippets.

@smalyshev smalyshev/76249.diff Secret
Created Apr 23, 2018

What would you like to do?
commit 06d309fd7a917575d65c7a6f4f57b0e6bb0f9711
Author: Stanislav Malyshev <>
Date: Sun Apr 22 21:26:06 2018 -0700
Fix bug #76249 - fail on invalid sequences
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 69dd8c1..fca5331 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;
+ } else {
+ php_error_docref(NULL, E_WARNING, "iconv stream filter (\"%s\"=>\"%s\"): invalid multibyte sequence", self->from_charset, self->to_charset);
+ goto out_failure;
diff --git a/ext/iconv/tests/bug76249.phpt b/ext/iconv/tests/bug76249.phpt
new file mode 100644
index 0000000..5a9d8f1
--- /dev/null
+++ b/ext/iconv/tests/bug76249.phpt
@@ -0,0 +1,16 @@
+Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequence)
+<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
+$fh = fopen('php://memory', 'rw');
+fwrite($fh, "abc");
+stream_filter_append($fh, 'convert.iconv.ucs-2/utf8//IGNORE', STREAM_FILTER_READ, []);
+echo stream_get_contents($fh);
+Warning: stream_get_contents(): iconv stream filter ("ucs-2"=>"utf8//IGNORE"): invalid multibyte sequence in %sbug76249.php on line %d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.