|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81222 ZipArchive Deletes 0-length file
Submitted: 2021-07-04 06:45 UTC Modified: 2021-07-05 11:57 UTC
From: eclipsechasers2 at yahoo dot com Assigned: cmb (profile)
Status: Wont fix Package: Filesystem function related
PHP Version: 7.4.21 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: eclipsechasers2 at yahoo dot com
New email:
PHP Version: OS:


 [2021-07-04 06:45 UTC] eclipsechasers2 at yahoo dot com
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:
$filename = '';
file_put_contents($filename, '');
$zip = new ZipArchive();

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

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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-05 01:05 UTC] 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-05 11:57 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-05 11:57 UTC]
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:

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
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 04:01:27 2023 UTC