Skip to content

Commit 92ba1e4

Browse files
committed
Prevent closing of innerstream of php://temp stream
Fixes GH-21221 Closes GH-21222
1 parent 80b1ede commit 92ba1e4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ PHP NEWS
139139
. Fixed bug GH-20370 (User stream filters could violate typed property
140140
constraints). (alexandre-daubois)
141141
. Allowed filtered streams to be casted as fd for select. (Jakub Zelenka)
142+
. Fixed bug GH-21221 (Prevent closing of innerstream of php://temp stream).
143+
(ilutov)
142144

143145
- Zip:
144146
. Fixed ZipArchive callback being called after executor has shut down.

ext/standard/tests/gh21221.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-21221: Prevent closing of innerstream of php://temp stream
3+
--CREDITS--
4+
chongwick
5+
--FILE--
6+
<?php
7+
8+
$f = fopen('php://temp', 'r+b');
9+
$resources = get_resources();
10+
fclose(end($resources));
11+
12+
?>
13+
--EXPECTF--
14+
Warning: fclose(): cannot close the provided stream, as it must not be manually closed in %s on line %d

main/streams/streams.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos
105105
php_stream *orig = enclosed->enclosing_stream;
106106

107107
php_stream_auto_cleanup(enclosed);
108+
enclosed->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
108109
enclosed->enclosing_stream = enclosing;
109110
return orig;
110111
}

0 commit comments

Comments
 (0)