From 8fdde690422cbaf6f3bbeea48de7c103505b5e0b Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:06:09 +0100 Subject: [PATCH 1/2] Relax possible E_ERROR condition to an Error exception --- ext/spl/spl_directory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index e36d11bdc105c..b7ab4fdd009ef 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1600,8 +1600,7 @@ PHP_METHOD(GlobIterator, count) RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); } else { /* This can happen by abusing destructors. */ - /* TODO: relax this from E_ERROR to an exception */ - php_error_docref(NULL, E_ERROR, "GlobIterator lost glob state"); + zend_throw_error(NULL, "GlobIterator lost glob state"); } } /* }}} */ From 1068c03c5093c58830e5ace845da38780b7c89b3 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:40:40 +0100 Subject: [PATCH 2/2] correction --- ext/spl/spl_directory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index b7ab4fdd009ef..5d523f596fb7d 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1596,12 +1596,12 @@ PHP_METHOD(GlobIterator, count) RETURN_THROWS(); } - if (spl_intern_is_glob(intern)) { - RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); - } else { - /* This can happen by abusing destructors. */ - zend_throw_error(NULL, "GlobIterator lost glob state"); - } + /* The spl_filesystem_object_get_method_check() function is called prior to calling this function. + * Therefore, the directory entry cannot be NULL. However, if it is not NULL, then it must be a glob iterator + * by construction. */ + ZEND_ASSERT(spl_intern_is_glob(intern)); + + RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); } /* }}} */ #endif /* HAVE_GLOB */