Commit ad44178a61f for php.net

commit ad44178a61fbe6690ff8fbc49bf53904c74eb4ec
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date:   Thu Sep 10 06:51:11 2026 -0400

    iconv: keep working converter when stream filter seek reset fails (#23594)

    php_iconv_stream_filter_seek() closed the filter's converter before
    knowing whether a replacement could be opened, then stored the failed
    iconv_open() result. That left self->cd as (iconv_t)-1 for every later
    read and write, and for the iconv_close() in the filter dtor. Open the
    replacement first and only swap it in on success.

    Closes GH-23594

diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index d9b54388a8f..af4717a00a4 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -2595,20 +2595,20 @@ static zend_result php_iconv_stream_filter_seek(
 		int whence)
 {
 	php_iconv_stream_filter *self = (php_iconv_stream_filter *)Z_PTR(filter->abstract);
+	iconv_t cd;

 	/* Reset stub buffer */
 	self->stub_len = 0;

-	/* Reset iconv conversion state by closing and reopening the converter */
-	iconv_close(self->cd);
-
-	self->cd = iconv_open(self->to_charset, self->from_charset);
-	if ((iconv_t)-1 == self->cd) {
+	cd = iconv_open(self->to_charset, self->from_charset);
+	if ((iconv_t)-1 == cd) {
 		php_error_docref(NULL, E_WARNING,
 				"iconv stream filter (\"%s\"=>\"%s\"): failed to reset conversion state",
 				self->from_charset, self->to_charset);
 		return FAILURE;
 	}
+	iconv_close(self->cd);
+	self->cd = cd;

 	return SUCCESS;
 }