diff --git a/NEWS b/NEWS index 043bfb73300..faae0d71369 100644 --- a/NEWS +++ b/NEWS @@ -54,6 +54,10 @@ PHP NEWS . Fixed bug GH-15982 (Assertion failure with array_find when references are involved). (nielsdos) +- Streams: + . Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c). + (nielsdos) + - Zip: . Added ZipArchive::ER_TRUNCATED_ZIP added in libzip 1.11. (Remi) diff --git a/ext/standard/tests/streams/gh15908.phpt b/ext/standard/tests/streams/gh15908.phpt new file mode 100644 index 00000000000..31714b20530 --- /dev/null +++ b/ext/standard/tests/streams/gh15908.phpt @@ -0,0 +1,38 @@ +--TEST-- +GH-15908 (leak / assertion failure in streams.c) +--CREDITS-- +YuanchengJiang +LuMingYinDetect +--FILE-- +s++ == 0) + return "a\nbb\ncc"; + return ""; + } + function stream_eof() { + return $this->s >= 2; + } +} +touch(__DIR__."/gh15908.tmp"); +stream_wrapper_register("test", "TestStream"); +$f = fopen("test://", "r"); +try { + file_put_contents(__DIR__."/gh15908.tmp", $f, FILE_USE_INCLUDE_PATH, $f); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +?> +--CLEAN-- + +--EXPECT-- +file_put_contents(): supplied resource is not a valid Stream-Context resource diff --git a/main/streams/streams.c b/main/streams/streams.c index f3fb5e3cda5..72f7bc3daeb 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -2211,7 +2211,9 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod options &= ~USE_PATH; } if (EG(exception)) { - ZEND_ASSERT(resolved_path == NULL); + if (resolved_path) { + zend_string_release_ex(resolved_path, false); + } return NULL; } }