From 95eaccd0bb901495323c36282d4e783556be1964 Mon Sep 17 00:00:00 2001 From: dinosaur Date: Tue, 14 Apr 2020 07:46:34 +0800 Subject: [PATCH] Fixed bug #79468 Close the stream filter resources when removing them from the stream. --- NEWS | 4 ++++ ext/standard/tests/filters/bug79468.phpt | 21 +++++++++++++++++++++ main/streams/streams.c | 6 ++++++ 3 files changed, 31 insertions(+) create mode 100644 ext/standard/tests/filters/bug79468.phpt diff --git a/NEWS b/NEWS index 9ebfbf16273..95e520e32ac 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ PHP NEWS . Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported). (Girgias) +- Standard: + . Fixed bug #79468 (SIGSEGV when closing stream handle with a stream filter + appended). (dinosaur) + 16 Apr 2020, PHP 7.3.17 - Core: diff --git a/ext/standard/tests/filters/bug79468.phpt b/ext/standard/tests/filters/bug79468.phpt new file mode 100644 index 00000000000..60a848ec016 --- /dev/null +++ b/ext/standard/tests/filters/bug79468.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #79468 SIGSEGV when closing stream handle with a stream filter appended +--SKIPIF-- + +--FILE-- +getMessage()); +} +?> +--EXPECTF-- +Warning: stream_filter_remove(): Invalid resource given, not a stream filter in %s on line %d diff --git a/main/streams/streams.c b/main/streams/streams.c index 5daf4fe83de..fb9c6800739 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -476,9 +476,15 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) { while (stream->readfilters.head) { + if (stream->readfilters.head->res != NULL) { + zend_list_close(stream->readfilters.head->res); + } php_stream_filter_remove(stream->readfilters.head, 1); } while (stream->writefilters.head) { + if (stream->writefilters.head->res != NULL) { + zend_list_close(stream->writefilters.head->res); + } php_stream_filter_remove(stream->writefilters.head, 1); }