Skip to content

Commit 95eaccd

Browse files
769344359nikic
authored andcommitted
Fixed bug #79468
Close the stream filter resources when removing them from the stream.
1 parent 8967588 commit 95eaccd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
1515
(Girgias)
1616

17+
- Standard:
18+
. Fixed bug #79468 (SIGSEGV when closing stream handle with a stream filter
19+
appended). (dinosaur)
20+
1721
16 Apr 2020, PHP 7.3.17
1822

1923
- Core:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #79468 SIGSEGV when closing stream handle with a stream filter appended
3+
--SKIPIF--
4+
<?php
5+
$filters = stream_get_filters();
6+
if(! in_array( "string.rot13", $filters )) die( "skip rot13 filter not available." );
7+
?>
8+
--FILE--
9+
<?php
10+
$fp = fopen('php://temp', 'rb');
11+
$rot13_filter = stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);
12+
fwrite($fp, "This is ");
13+
fclose($fp);
14+
try {
15+
stream_filter_remove($rot13_filter);
16+
} catch (\Throwable $e) {
17+
var_dump($e->getMessage());
18+
}
19+
?>
20+
--EXPECTF--
21+
Warning: stream_filter_remove(): Invalid resource given, not a stream filter in %s on line %d

main/streams/streams.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,15 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
476476

477477
if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) {
478478
while (stream->readfilters.head) {
479+
if (stream->readfilters.head->res != NULL) {
480+
zend_list_close(stream->readfilters.head->res);
481+
}
479482
php_stream_filter_remove(stream->readfilters.head, 1);
480483
}
481484
while (stream->writefilters.head) {
485+
if (stream->writefilters.head->res != NULL) {
486+
zend_list_close(stream->writefilters.head->res);
487+
}
482488
php_stream_filter_remove(stream->writefilters.head, 1);
483489
}
484490

0 commit comments

Comments
 (0)