You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ZipArchive deletes zip file with no contents and doesn't update stat cache #8781
perhaps since empty file are not valid zip archive
I don't think this is true. On Windows, I can create an empty.zip via the explorer, and the specification says:
4.1.2 ZIP files SHOULD contain at least one file and MAY contain multiple files.
"SHOULD contain" is not "MUST contain".
We may consider to still create such an empty archive, even if libzip would delete the file. Or maybe upstream would reconsider the behavior for empty archives.
Yes, but the example use a "empty file" (tempnam) which is not a valid archive.
Oh, right!
And indeed, the library doesn't allow to create an empty archive, but I don't think we can fix this in the extension.
Thinking about it, that should really be fixed upstream. For instance, given that I have an archive, and delete some entries, after ::close() the archive is gone, if there are no more entries. At least that happens with libzip 1.7.3 (I'm feeling bad, because winlibs are so far behind).
Activity
remicollet commentedon Jun 15, 2022
Confirmed
This the default behavior of the libzip library, (perhaps since empty file are not valid zip archive), so nothing we can change in php
PR pending
remicollet commentedon Jun 15, 2022
Fixed in standalone pecl extension
pierrejoye/php_zip@fac6809
Fix phpGH-8781 #ZipArchive deletes zip file with no contents and does…
Fix phpGH-8781 #ZipArchive deletes zip file with no contents and does…
remicollet commentedon Jun 15, 2022
See PR #8783
cmb69 commentedon Jun 15, 2022
I don't think this is true. On Windows, I can create an empty.zip via the explorer, and the specification says:
"SHOULD contain" is not "MUST contain".
We may consider to still create such an empty archive, even if libzip would delete the file. Or maybe upstream would reconsider the behavior for empty archives.
remicollet commentedon Jun 15, 2022
I mean "empty file" (size=0) are not valid, not about "empty archive" ;)
cmb69 commentedon Jun 15, 2022
Yeah, but this ticket is about empty archives:
remicollet commentedon Jun 15, 2022
Yes, but the example use a "empty file" (tempnam) which is not a valid archive.
And indeed, the library doesn't allow to create an empty archive, but I don't think we can fix this in the extension.
P.S. opening an empty archive works (and it is not deleted during the close)
For memory, upstream code: https://github.com/nih-at/libzip/blob/v1.9.0/lib/zip_close.c#L65
cmb69 commentedon Jun 15, 2022
Oh, right!
Thinking about it, that should really be fixed upstream. For instance, given that I have an archive, and delete some entries, after
::close()the archive is gone, if there are no more entries. At least that happens with libzip 1.7.3 (I'm feeling bad, because winlibs are so far behind).remicollet commentedon Jun 15, 2022
libzip discussion nih-at/libzip#299
Fix GH-8781 ZipArchive::close deletes zip file without updating stat …
Merge branch 'PHP-8.0' into PHP-8.1
Merge branch 'PHP-8.1'
remicollet commentedon Jun 15, 2022
Followup: add documentation of library expected /documented behavior in our documentation
php/doc-en#1628