php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eclipsechasers2 at yahoo dot com
New email:
PHP Version: OS:

 

 [2021-07-04 06:45 UTC] 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.


Patches

Pull Requests

History

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] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-05 11:57 UTC] cmb@php.net
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).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 11:01:28 2024 UTC