diff --git a/NEWS b/NEWS index c167074f0b8..efd92cb011a 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ PHP NEWS - Zip: . Fixed bug GH-18431 (Registering ZIP progress callback twice doesn't work). (nielsdos) + . Fixed bug GH-18438 (Handling of empty data and errors in + ZipArchive::addPattern). (nielsdos) 08 May 2025, PHP 8.3.21 diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 388b3485cbd..62f51ce9f35 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -761,6 +761,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val re = pcre_get_compiled_regex(regexp, &capture_count); if (!re) { + for (i = 0; i < files_cnt; i++) { + zend_string_release_ex(namelist[i], 0); + } + efree(namelist); php_error_docref(NULL, E_WARNING, "Invalid expression"); return -1; } @@ -1837,6 +1841,10 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* #endif } } + } else if (found == 0) { + RETURN_EMPTY_ARRAY(); + } else { + RETURN_FALSE; } } /* }}} */ diff --git a/ext/zip/tests/gh18438.phpt b/ext/zip/tests/gh18438.phpt new file mode 100644 index 00000000000..b997931c708 --- /dev/null +++ b/ext/zip/tests/gh18438.phpt @@ -0,0 +1,50 @@ +--TEST-- +GH-18438 (Handling of empty data and errors in ZipArchive::addPattern) +--EXTENSIONS-- +zip +--SKIPIF-- + +--FILE-- +open($file, ZIPARCHIVE::CREATE); +var_dump($zip->addPattern('/nomatches/')); +var_dump($zip->addPattern('/invalid')); + +stream_wrapper_register('custom', CustomStreamWrapper::class); +var_dump($zip->addPattern('/invalid', 'custom://')); +?> +--CLEAN-- + +--EXPECTF-- +array(0) { +} + +Warning: ZipArchive::addPattern(): No ending delimiter '/' found in %s on line %d + +Warning: ZipArchive::addPattern(): Invalid expression in %s on line %d +bool(false) +array(0) { +}