Skip to content

Commit 0b96441

Browse files
authored
ext/iconv/tests/bug76249.phpt: fallback for non-GNU iconv() (php#22552)
This test fails on musl, where iconv trips over the //IGNORE suffix. It is not obvious that //IGNORE is required to trigger the issue in the first place, but since we are ensuring that a security bug is fixed, it is better to include it where possible. This commit updates the test to append //IGNORE only on the two GNU iconv implementations that are known to support it. POSIX specifies its behavior, but leaves overall support optional.
1 parent 5ec033c commit 0b96441

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

ext/iconv/tests/bug76249.phpt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@ Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequen
44
iconv
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');
819
fwrite($fh, "abc");
920
rewind($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
}
1324
var_dump(stream_get_contents($fh));
1425
?>
1526
DONE
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\) ""
1930
DONE

0 commit comments

Comments
 (0)