diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 388b3485cbd94..62f51ce9f35f3 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 0000000000000..b997931c7088a --- /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) { +}