Bug #66786 [NEW]: ZipArchive fails when an added file is removed before close()

From: Date: Wed, 26 Feb 2014 23:16:50 +0000
Subject: Bug #66786 [NEW]: ZipArchive fails when an added file is removed before close()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184447@lists.php.net to get a copy of this message
From:             lists dot ban at herbesfolles dot org
Operating system: Linux (Debian Sid), probably any
PHP version:      master-Git-2014-02-26 (Git)
Package:          Zip Related
Bug Type:         Bug
Bug description:ZipArchive fails when an added file is removed before close()

Description:
------------
When adding a file to a Zip archive, the user expects to be able to
unlink the original file without issues.  The documentation on
ZipArchive::addFile() even has a (admittedly strangely worded) note
suggesting it would work:

    "When a file is set to be added to the archive, PHP will attempt to
lock the file and it is only released once the ZIP operation is done. In
short, it means you can first delete an added file after the archive is
closed."

However, in practice it doesn't work, and depending on the PHP version
(or build?) it could even silently fail.  PHP 5.5.9 from Debian Sid
fails on ZipArchive::close() with StatusString as "No error";  PHP
5.7.0-dev from today Git don't even report any problem.  In any case,
the result zip is not created.

This is both with system (0.11.2) and bundled libzip.

Test script:
---------------
$zip = new ZipArchive();
$zip->open('output.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
file_put_contents('dummy.txt', 'hello world');
if (! $zip->addFile('dummy.txt'))
	echo "addFile() failed\n";
unlink('dummy.txt');
if (! $zip->close())
	echo "close() failed\n";
echo "output.zip size: ", filesize('output.zip'), "\n";
@unlink('output.zip');

Expected result:
----------------
output.zip size: 129

Actual result:
--------------
output.zip size: 
Warning: filesize(): stat failed for output.zip in zipbug.php on line 9



-- 
Edit bug report at https://bugs.php.net/bug.php?id=66786&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=66786&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=66786&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=66786&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=66786&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=66786&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=66786&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=66786&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=66786&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=66786&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=66786&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=66786&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=66786&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=66786&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66786&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=66786&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=66786&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=66786&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66786&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=66786&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=66786&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#184447) next »