[php-src] PHP-8.4: ext/iconv/tests/bug76249.phpt: fallback for non-GNU iconv() (#22552)

Michael Orlitzky via GitHub <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Michael Orlitzky (orlitzky)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-07-08T15:41:21+01:00

Commit: https://github.com/php/php-src/commit/0b9644161c5ff23adda2ee28af86ae11307cbc2b
Raw diff: https://github.com/php/php-src/commit/0b9644161c5ff23adda2ee28af86ae11307cbc2b.diff

ext/iconv/tests/bug76249.phpt: fallback for non-GNU iconv() (#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.

Changed paths:
  M  ext/iconv/tests/bug76249.phpt


Diff:

diff --git a/ext/iconv/tests/bug76249.phpt b/ext/iconv/tests/bug76249.phpt
index 37608ccc0447..2fa9b8cc0500 100644
--- a/ext/iconv/tests/bug76249.phpt
+++ b/ext/iconv/tests/bug76249.phpt
@@ -4,16 +4,27 @@ Bug #76249 (stream filter convert.iconv leads to infinite loop on invalid sequen
 iconv
 --FILE--
 <?php
+$ignore = "";
+if (ICONV_IMPL == "libiconv" || ICONV_IMPL == "glibc") {
+    // The original bug report uses "//IGNORE", and the bug itself
+    // involves the return value and errno from iconv(), so in the
+    // interest of fidelity we include the suffix on systems like the
+    // one where the bug was reported. On other systems however, the
+    // "//IGNORE" suffix may not be supported, and this is allowed by
+    // POSIX (musl in particular does not support it).
+    $ignore = "//IGNORE";
+}
+
 $fh = fopen('php://memory', 'rw');
 fwrite($fh, "abc");
 rewind($fh);
-if (false === @stream_filter_append($fh, 'convert.iconv.ucs-2/utf8//IGNORE', STREAM_FILTER_READ, [])) {
-    stream_filter_append($fh, 'convert.iconv.ucs-2/utf-8//IGNORE', STREAM_FILTER_READ, []);
+if (false === @stream_filter_append($fh, "convert.iconv.ucs-2/utf8{$ignore}", STREAM_FILTER_READ, [])) {
+    stream_filter_append($fh, "convert.iconv.ucs-2/utf-8{$ignore}", STREAM_FILTER_READ, []);
 }
 var_dump(stream_get_contents($fh));
 ?>
 DONE
---EXPECTF--
-Warning: stream_get_contents(): iconv stream filter ("ucs-2"=>"utf%A8//IGNORE"): invalid multibyte sequence in %sbug76249.php on line %d
-string(0) ""
+--EXPECTREGEX--
+Warning: stream_get_contents\(\): iconv stream filter \("ucs-2"=>"utf-?8(\/\/IGNORE)?"\): invalid multibyte sequence in .*bug76249\.php on line \d+
+string\(0\) ""
 DONE
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.