[php-src] master: iconv: keep working converter when stream filter seek reset fails (#23594)

From: Date: Thu, 10 Sep 2026 10:51:14 +0000
Subject: [php-src] master: iconv: keep working converter when stream filter seek reset fails (#23594)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141160@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Committer: GitHub (web-flow) Pusher: iliaal Date: 2026-09-10T06:51:11-04:00 Commit: https://github.com/php/php-src/commit/ad44178a61fbe6690ff8fbc49bf53904c74eb4ec Raw diff: https://github.com/php/php-src/commit/ad44178a61fbe6690ff8fbc49bf53904c74eb4ec.diff 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 Changed paths: M ext/iconv/iconv.c Diff: diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index d9b54388a8f8..af4717a00a48 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; }

« previous php.cvs (#141160) next »