diff --git a/NEWS b/NEWS index ae0f6f3e8ff..1f084e98cb3 100644 --- a/NEWS +++ b/NEWS @@ -139,6 +139,8 @@ PHP NEWS . Fixed bug GH-20370 (User stream filters could violate typed property constraints). (alexandre-daubois) . Allowed filtered streams to be casted as fd for select. (Jakub Zelenka) + . Fixed bug GH-21221 (Prevent closing of innerstream of php://temp stream). + (ilutov) - Zip: . Fixed ZipArchive callback being called after executor has shut down. diff --git a/ext/standard/tests/gh21221.phpt b/ext/standard/tests/gh21221.phpt new file mode 100644 index 00000000000..8435b480347 --- /dev/null +++ b/ext/standard/tests/gh21221.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-21221: Prevent closing of innerstream of php://temp stream +--CREDITS-- +chongwick +--FILE-- + +--EXPECTF-- +Warning: fclose(): cannot close the provided stream, as it must not be manually closed in %s on line %d diff --git a/main/streams/streams.c b/main/streams/streams.c index 85d2947c28a..32c7ba99f58 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -105,6 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos php_stream *orig = enclosed->enclosing_stream; php_stream_auto_cleanup(enclosed); + enclosed->flags |= PHP_STREAM_FLAG_NO_FCLOSE; enclosed->enclosing_stream = enclosing; return orig; }