Fixed ErrorException: [E_WARNING] ZipArchive::addFile() when building release with libzip5 1.6.0

ivp

Active member
Affected version
2.1.7
Updated yum packages to:

libzip5-1.6.0-1.el7.remi.x86_64
php-pecl-zip-1.16.0-1.el7.remi.7.3.x86_64
libarchive-3.1.2-14.el7_7.x86_64

When running php cmd.php xf-addon:build-release ... seeing error:
ErrorException: [E_WARNING] ZipArchive::addFile(): Invalid or uninitialized Zip object src/XF/Service/AddOn/ReleaseBuilder.php:413

The whole output:
Code:
Performing add-on export.
Exporting data for ...
Written successfully.
Attempting to validate addon.json file...
JSON file validates successfully!

Building release ZIP.

In ReleaseBuilder.php line 413:
                                                                        
  [E_WARNING] ZipArchive::addFile(): Invalid or uninitialized Zip object
                                                                        

xf-addon:build-release [--skip-hashes] [--] <id>

Admin panel shows "ZipArchive support: Yes".

Sample code works fine:
Code:
<?php

$zip = new ZipArchive;
$zip->open('test.zip', ZipArchive::CREATE);
$zip->addFile('test.txt');
$zip->close();
 
Last edited:
Found the cause.

Function $zipArchive->open($this->tempFile, \ZipArchive::CREATE) fails with error code 19 (Not a zip archive).

The fix is to add ".zip" extension to $this->tempFile.

There should be some error check for output of $zipArchive->open, also.
 
I am also affected by this issue. I can confirm that changing the relevant line of src/XF/Service/AddOn/ReleaseBuilder.php to $this->tempFile = File::getTempFile() . '.zip'; fixes the issue.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.8).

Change log:
Use \ZipArchive::OVERWRITE flag when creating add-on zip to maintain compatibility with newer libzip versions
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom