Bug #81222 [Opn->Wfx]: ZipArchive Deletes 0-length file

From: Date: Mon, 05 Jul 2021 11:57:49 +0000
Subject: Bug #81222 [Opn->Wfx]: ZipArchive Deletes 0-length file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234801@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81222&edit=1

 ID:                 81222
 Updated by:         cmb@php.net
 Reported by:        eclipsechasers2 at yahoo dot com
 Summary:            ZipArchive Deletes 0-length file
-Status:             Open
+Status:             Wont fix
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Windows 10
 PHP Version:        7.4.21
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

First, this is not related to the OS, but rather to the libzip
version in use (an empty file is deleted as of libzip 1.0.0).

Anyhow, this is caused by trying to keep compatibility with libzip
< 1.6.0, which does not accept empty files as valid zip archives
any longer, what had been reported as bug #79296, and mitigated:
<https://bugs.php.net/79296#1584700784>.

The behavior regarding empty archives which are not updated is
inconvenient, but you can set the ZipArchive::RDONLY flag if
your're not planning to update the archive, in which case the
archive will not be opened in the first place
(ZipArchive::ER_NOZIP).


Previous Comments:
------------------------------------------------------------------------
[2021-07-05 01:05:33] eclipsechasers2 at yahoo dot com

It looks like the problem can occur with non-zero-length files as well, though not as predictably.

------------------------------------------------------------------------
[2021-07-04 06:45:13] eclipsechasers2 at yahoo dot com

Description:
------------
On Windows, when a zero-length file is opened as a ZipArchive, the file is deleted when the zip is
closed. This seems to happen in all releases of PHP. It does not seem to happen on Linux systems.

Test script:
---------------
<?php
$filename = 'zerolengthfile.zip';
file_put_contents($filename, '');
assert(file_exists($filename));
$zip = new ZipArchive();
$zip->open($filename);
$zip->close();
assert(file_exists($filename));

Expected result:
----------------
I expect the assert at the end to not issue a message. I also expect zerolengthfile.zip to exist.

Actual result:
--------------
Warning: assert(): assert(file_exists($filename)) failed in C:\phpexceltest\Owen
\testfile2.php on line 8

zerolengthfile.zip does not exist

If the $zip->close() statement is removed, the assert at the end does not issue a message.
Nevertheless, zerolengthfile.zip does not exist when the script terminates.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81222&edit=1


Thread (3 messages)

« previous php.bugs (#234801) next »