Skip to content

Commit 94c2ae6

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-15908 and GH-15026: leak / assertion failure in streams.c
2 parents 915d1f6 + 018c0b3 commit 94c2ae6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ PHP NEWS
2020
. Fixed bug GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c).
2121
(nielsdos)
2222

23+
- Streams:
24+
. Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c).
25+
(nielsdos)
26+
2327
12 Sep 2024, PHP 8.3.12
2428

2529
- Core:
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-15908 (leak / assertion failure in streams.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
LuMingYinDetect
6+
--FILE--
7+
<?php
8+
class TestStream {
9+
public $context;
10+
private $s = 0;
11+
function stream_open($path, $mode, $options, &$opened_path) {
12+
return true;
13+
}
14+
function stream_read($count) {
15+
echo "Read done\n";
16+
if ($this->s++ == 0)
17+
return "a\nbb\ncc";
18+
return "";
19+
}
20+
function stream_eof() {
21+
return $this->s >= 2;
22+
}
23+
}
24+
touch(__DIR__."/gh15908.tmp");
25+
stream_wrapper_register("test", "TestStream");
26+
$f = fopen("test://", "r");
27+
try {
28+
file_put_contents(__DIR__."/gh15908.tmp", $f, FILE_USE_INCLUDE_PATH, $f);
29+
} catch (Error $e) {
30+
echo $e->getMessage(), "\n";
31+
}
32+
?>
33+
--CLEAN--
34+
<?php
35+
@unlink(__DIR__."/gh15908.tmp");
36+
?>
37+
--EXPECT--
38+
file_put_contents(): supplied resource is not a valid Stream-Context resource

main/streams/streams.c

+3
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
22112211
options &= ~USE_PATH;
22122212
}
22132213
if (EG(exception)) {
2214+
if (resolved_path) {
2215+
zend_string_release_ex(resolved_path, false);
2216+
}
22142217
return NULL;
22152218
}
22162219
}

0 commit comments

Comments
 (0)