Skip to content

Commit 018c0b3

Browse files
committed
Fix GH-15908 and GH-15026: leak / assertion failure in streams.c
This was first reported as a leak in GH-15026, but was mistakingly believed to be a false positive. Then an assertion was added and it got triggered in GH-15908. This fixes the leak. Upon merging into master the assertion should be removed as well. Closes GH-15924.
1 parent 18ab97b commit 018c0b3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
. Fixed bug GH-15613 (overflow on unpack call hex string repeater).
2727
(David Carlier)
2828

29+
- Streams:
30+
. Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c).
31+
(nielsdos)
32+
2933
- XML:
3034
. Fixed bug GH-15868 (Assertion failure in xml_parse_into_struct after
3135
exception). (nielsdos)
Lines changed: 38 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
21752175
options &= ~USE_PATH;
21762176
}
21772177
if (EG(exception)) {
2178+
if (resolved_path) {
2179+
zend_string_release_ex(resolved_path, false);
2180+
}
21782181
return NULL;
21792182
}
21802183
}

0 commit comments

Comments
 (0)