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

Affected version
2.1.7

ivanp

Active member
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:

ivanp

Active member
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.
 

DragonByte Tech

Well-known member
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.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
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