doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

zip extension only acts when closing the archive

Open chaar123 opened this issue 1 year ago • 5 comments

Description

The following code:

<?php
$archive = new ZipArchive();
// case 1: $name = '/notexistingfilename' 
// case 2: $name = '/notexisting/notexistingfilename'
$res = $archive->open($name, ZipArchive::CREATE); 
if ($res !== true) {
// ...........................
}
// ...........
$archive->close();

Resulted in this output:

case 1
ZipArchive::close(): Failure to create temporary file: Permission denied 
case 2
ZipArchive::close(): Failure to create temporary file: No such file or directory

But I expected this output instead:

case 1
ZipArchive::open(): Failure to create temporary file: Permission denied 
case 2
ZipArchive::open(): Failure to create temporary file: No such file or directory

PHP Version

PHP 8.3.7

Operating System

Fedora 39

chaar123 avatar Sep 05 '24 14:09 chaar123

It is not a bug but it is quite confusing.

chaar123 avatar Sep 05 '24 14:09 chaar123

yes ZipArchive::open does not raise an E_WARNING unlike ZipArchive::close. Can't really say if this is the proper behavior/any room for improvements, @nielsdos thoughts ?

devnexen avatar Sep 05 '24 14:09 devnexen

This is what is reported by libzip library where everything is done when close is called Probably nothing we can really change on PHP side

remicollet avatar Sep 05 '24 15:09 remicollet

Maybe we can improve the documentation; transferring the ticket to doc-en might be in reasonable.

cmb69 avatar Sep 05 '24 16:09 cmb69

If this comes from libzip, I say: move to docs issue. Anyway, even if we were to add checks at open time, we might run into TOCTOU related issues, so let's not do that.

ndossche avatar Sep 05 '24 17:09 ndossche