@@ -4,16 +4,27 @@ Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequen
44iconv
55--FILE--
66<?php
7+ $ ignore = "" ;
8+ if (ICONV_IMPL == "libiconv " || ICONV_IMPL == "glibc " ) {
9+ // The original bug report uses "//IGNORE", and the bug itself
10+ // involves the return value and errno from iconv(), so in the
11+ // interest of fidelity we include the suffix on systems like the
12+ // one where the bug was reported. On other systems however, the
13+ // "//IGNORE" suffix may not be supported, and this is allowed by
14+ // POSIX (musl in particular does not support it).
15+ $ ignore = "//IGNORE " ;
16+ }
17+
718$ fh = fopen ('php://memory ' , 'rw ' );
819fwrite ($ fh , "abc " );
920rewind ($ fh );
10- if (false === @stream_filter_append ($ fh , ' convert.iconv.ucs-2/utf8//IGNORE ' , STREAM_FILTER_READ , [])) {
11- stream_filter_append ($ fh , ' convert.iconv.ucs-2/utf-8//IGNORE ' , STREAM_FILTER_READ , []);
21+ if (false === @stream_filter_append ($ fh , " convert.iconv.ucs-2/utf8 { $ ignore }" , STREAM_FILTER_READ , [])) {
22+ stream_filter_append ($ fh , " convert.iconv.ucs-2/utf-8 { $ ignore }" , STREAM_FILTER_READ , []);
1223}
1324var_dump (stream_get_contents ($ fh ));
1425?>
1526DONE
16- --EXPECTF --
17- Warning: stream_get_contents( ): iconv stream filter ("ucs-2"=>"utf%A8/ /IGNORE" ): invalid multibyte sequence in %sbug76249. php on line %d
18- string(0 ) ""
27+ --EXPECTREGEX --
28+ Warning: stream_get_contents\(\ ): iconv stream filter \ ("ucs-2"=>"utf-?8(\/\ /IGNORE)?"\ ): invalid multibyte sequence in .*bug76249\. php on line \d+
29+ string\(0\ ) ""
1930DONE
0 commit comments