Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
/* }}} */
Expand Down
50 changes: 50 additions & 0 deletions ext/zip/tests/gh18438.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
GH-18438 (Handling of empty data and errors in ZipArchive::addPattern)
--EXTENSIONS--
zip
--SKIPIF--
<?php
if (PHP_ZTS) die("skip not for ZTS because of path prefixing breaking custom wrapper test");
?>
--FILE--
<?php
class CustomStreamWrapper {
public $context;
function dir_closedir(): bool {
return true;
}
function dir_opendir(string $path, int $options): bool {
return true;
}
function dir_readdir(): string|false {
return false;
}
function dir_rewinddir(): bool {
return false;
}
}

$file = __DIR__ . '/gh18438.zip';
$zip = new ZipArchive;
$zip->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--
<?php
$file = __DIR__ . '/gh18438.zip';
@unlink($file);
?>
--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) {
}
Loading