From 8317f633cb5028b2d9a8919f7b6b9ede50ad32bd Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Sun, 9 Jan 2022 14:32:23 -0600 Subject: [PATCH] Prevent fclose on underlying SplFileObject file stream. --- ext/spl/spl_directory.c | 3 +++ ext/spl/tests/bug81691.phpt | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 ext/spl/tests/bug81691.phpt diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 5be57bccbf852..99a0fcb989474 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -333,6 +333,9 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool return FAILURE; } + /* prevent closing the stream outside of SplFileObject */ + intern->u.file.stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE; + /* if (intern->u.file.zcontext) { //zend_list_addref(Z_RES_VAL(intern->u.file.zcontext)); diff --git a/ext/spl/tests/bug81691.phpt b/ext/spl/tests/bug81691.phpt new file mode 100644 index 0000000000000..597e37a9c8218 --- /dev/null +++ b/ext/spl/tests/bug81691.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #81691 fclose on SplFileObject stream +--FILE-- +fgets()); + +?> +--EXPECTF-- +Warning: fclose(): %d is not a valid stream resource in %s on line %d +string(6) "