Bug #66786 [Opn->Fbk]: ZipArchive fails when an added file is removed before close()
Edit report at https://bugs.php.net/bug.php?id=66786&edit=1
ID: 66786
Updated by: ab@php.net
Reported by: lists dot ban at herbesfolles dot org
Summary: ZipArchive fails when an added file is removed
before close()
-Status: Open
+Status: Feedback
Type: Bug
Package: Zip Related
Operating System: Linux (Debian Sid), probably any
PHP Version: master-Git-2014-02-26 (Git)
Block user comment: N
Private report: N
New Comment:
Maybe I misread it, but according to the quote you gave it shouldn't work:
"you can first delete an added file after the archive is closed"
In 5.5 there's libzip-0.10.1 and in 5.6+ is libzip 0.11.2 . Looking at those code, the diff
between the current situation and your patch were only that you pass an open descriptor. When the
file is deleted, the descriptor will be still open, true. That however will not work on Windows, so
different handling. Were it not safer just using addFromString?
Previous Comments:
------------------------------------------------------------------------
[2014-02-26 23:16:49] lists dot ban at herbesfolles dot org
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 this bug report at https://bugs.php.net/bug.php?id=66786&edit=1
Thread (5 messages)