|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53856 zipArchive::addPattern requires path parameter
Submitted: 2011-01-27 16:46 UTC Modified: 2016-09-06 13:53 UTC
From: Assigned: cmb (profile)
Status: Closed Package: Zip Related
PHP Version: 5.3.5 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2011-01-27 16:46 UTC]
php --rf zipArchive::addPattern tells us that the path is optional. This is 
confirmed by the parameter parsing.

But, at least on windows, if no path is supplied, with a pattern that will include 
everything, no files are added.

Setting the path to the current directory (for example) will include all files in 
that directory (using the same regex).

Test script:
$zip = new ZipArchive;

if (True === $zip->open('./', ZIPARCHIVE::CREATE)) {
  	'Add all files with no path param', PHP_EOL,
  	print_r($zip->addPattern('/.*/'), True), PHP_EOL,
  	'Number of files : ', $zip->numFiles, PHP_EOL,
  	'Add all files in current path param', PHP_EOL,
  	print_r($zip->addPattern('/.*/', '.'), True), PHP_EOL,
  	'Number of files : ', $zip->numFiles, PHP_EOL;

Expected result:
Add all files with no path param
    [0] => .\25.BAT
    [88] => .\upxit.bat

Number of files : 89
Add all files in current path param
    [0] => .\25.BAT
    [88] => .\upxit.bat

Number of files : 178

Actual result:
Add all files with no path param

Number of files : 0
Add all files in current path param
    [0] => .\25.BAT
    [88] => .\upxit.bat

Number of files : 89


zip_addPattern.patch (last revision 2011-01-27 15:46 UTC by rquadling)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-27 16:55 UTC]
The supplied patch makes the path parameter mandatory.
 [2011-01-27 16:57 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pajoye
 [2011-01-27 16:57 UTC]
It should be optional, making it mandatory is not correct.
 [2011-01-27 17:05 UTC]
If it is optional, then with a pattern that says include everything, what path 
should be examined? What is the default path?

If it is supposed to be optional, then I'd guess the current path should be the 
 [2011-01-27 17:10 UTC]
If the pattern begins with an absolute path or not is the key part. I will take 
care of that bug (something else to check as well).
 [2015-08-20 22:20 UTC]
Not sure what happened in the meantime, but thread-safe Windows
builds of recent versions even segfault due to null pointer
dereferencing, if the $path parameter is omitted, see

Wouldn't it be reasonable to use the default path (".") instead of
NULL in php_zip_add_from_pattern()?
 [2016-09-06 13:53 UTC]
-Status: Assigned +Status: Closed -Assigned To: pajoye +Assigned To: cmb
 [2016-09-06 13:53 UTC]
The segfault issue has been resolved by fixing bug #72660, and
that also solves this issue by actually defaulting path to '.'.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 16:05:57 2022 UTC