#47023 [NEW]: ZipArchive fails under certain circumstances
| From: | cristi at imagis dot ro | Date: | Wed, 07 Jan 2009 09:24:45 +0000 |
| Subject: | #47023 [NEW]: ZipArchive fails under certain circumstances | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-132611@lists.php.net to get a copy of this message | ||
From: cristi at imagis dot ro
Operating system: Windows XP SP3
PHP version: 5.2.8
PHP Bug Type: Zip Related
Bug description: ZipArchive fails under certain circumstances
Description:
------------
I am experiencing some problems with ZipArchive, using PHP 5.2.8, with
php_zip supplied with this distribution. I am trying to archive couple of
folders and files using ZipArchive.
If i am replacing php_zip.dll with php_zip.dll from PHP 5.2.6 it works
without problems.
Testing same code using a PHP 5.2.7 installation (with php_zip.dll of
5.2.7) crashes archive also (see Expected Results section).
Reproduce code:
---------------
class My_ZipArchive extends ZipArchive
{
public function addDir($filename, $localname)
{
// Adds a directory recursivelly, keeping the same structure.
// @param string $filename The path to the file to add.
// @param string $localname Local name inside ZIP archive.
if($localname == NULL || empty($localname))
$localpath = "";
else
{
$localpath = $localname . '/';
$this->addEmptyDir($localname);
}
$iter = new DirectoryIterator($filename);
foreach($iter as $file)
{
// Only zip real files: no dots, no links.
if ($file->isDot() || (!$file->isFile() && !$file->isDir())) {
continue;
}
$method = $file->isFile() ? 'addFile' : 'addDir';
echo $file->getPathname().' - '.$method.'<br />';
$this->$method($file->getPathname(),
$localpath.$file->getFilename());
}
}
}
try
{
//create output archive
$zip = new My_ZipArchive();
$zip->open( 'archive.zip', ZIPARCHIVE::CREATE);
$zip->addDir( 'd:\_Work\test\output', '');
$result = $zip->close();
//finish create output archive
}
catch(Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
exit($result.'finished');
Expected result:
----------------
This code should make a zip with my files.
Actual result:
--------------
If i have 3 .php files to add them to zip i got a corrupted archive.
If i remove one of them i got a good zip archive.
If i am opening corrupted archive with a zip utility archive doesn't seems
to have any files within or is reported directly as corrupted. If i am
using a repair tool i got a working archive.
--
Edit bug report at http://bugs.php.net/?id=47023&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47023&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47023&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47023&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47023&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47023&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47023&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47023&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47023&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47023&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47023&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47023&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47023&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47023&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47023&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47023&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47023&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47023&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47023&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47023&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47023&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47023&r=mysqlcfg