Skip to content

Commit 44357b1

Browse files
committed
iconv: keep working converter when stream filter seek reset fails
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.
1 parent 1d004f0 commit 44357b1

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

ext/iconv/iconv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,20 +2595,20 @@ static zend_result php_iconv_stream_filter_seek(
25952595
int whence)
25962596
{
25972597
php_iconv_stream_filter *self = (php_iconv_stream_filter *)Z_PTR(filter->abstract);
2598+
iconv_t cd;
25982599

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

2602-
/* Reset iconv conversion state by closing and reopening the converter */
2603-
iconv_close(self->cd);
2604-
2605-
self->cd = iconv_open(self->to_charset, self->from_charset);
2606-
if ((iconv_t)-1 == self->cd) {
2603+
cd = iconv_open(self->to_charset, self->from_charset);
2604+
if ((iconv_t)-1 == cd) {
26072605
php_error_docref(NULL, E_WARNING,
26082606
"iconv stream filter (\"%s\"=>\"%s\"): failed to reset conversion state",
26092607
self->from_charset, self->to_charset);
26102608
return FAILURE;
26112609
}
2610+
iconv_close(self->cd);
2611+
self->cd = cd;
26122612

26132613
return SUCCESS;
26142614
}

0 commit comments

Comments
 (0)