Opened 12 years ago
Last modified 10 days ago
#30963 new defect (bug)
Wrong error message when uploading non-zip files on the plugin upload page
| Reported by: | jnhghy | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Plugins | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | administration |
Description
If you go to plugins -> upload plugin and you try to insall a .php file instead of a zip file you get this error message: Abort class-pclzip.php : Missing zlib extensions.
This error message is bad, zlib extensions are not missing, the file type is wrong.
Also this message is missing translation support (I might be wrong on this).
Attachments (4)
Change History (15)
#3
in reply to: ↑ 2
@
12 years ago
Replying to dd32:
The error outlined in the ticket here,
Abort class-pclzip.php : Missing zlib extensionsoccurs when the PHP installation is missing bothZipArchivesupport, and doesn't containgzopen()(ie. missing zlib extension, or that ubuntu bug #30213). In this case all update-related functionality doesn't work, and we don't appear to check support properly.
Small clarification: If the install has ZipArchive support, but no gzopen() available, and a non-zip is uploaded, it'll also hit the above conditional, which is currently wrapped in a die()
#4
@
9 years ago
- Keywords needs-patch added
@jnhghy If you were interestedin submitting a patch to improve this error message, I could get behind that.
#6
@
3 weeks ago
- Keywords close added; needs-patch removed
- Summary Wrong error message when uploading non-zip files on the plugin upload page → I think this error was fixed earlier
#7
@
3 weeks ago
- Keywords needs-patch added; close removed
- Summary I think this error was fixed earlier → I'm not skilled enough in WP to have a privileges of closing tickets. Just wanted to highlight that the error seems had been resolved
#8
@
3 weeks ago
- Summary I'm not skilled enough in WP to have a privileges of closing tickets. Just wanted to highlight that the error seems had been resolved → Wrong error message when uploading non-zip files on the plugin upload page
This ticket was mentioned in PR #13613 on WordPress/wordpress-develop by @irozum.
3 weeks ago
#9
- Keywords has-patch has-unit-tests added; needs-patch removed
What this fixes
When a PHP installation is missing both the ZipArchive class and the zlib extension (gzopen()), unzip_file() falls through to the bundled PclZip library, whose constructor calls die('Abort class-pclzip.php : Missing zlib extensions'). This is an untranslated, unstyled fatal error rather than the usual WP_Error that callers (like the plugin/theme upload screens) expect and render nicely.
The fix
- Added a check at the top of
_unzip_file_pclzip()insrc/wp-admin/includes/file.phpthat detects the missing zlib extension before ever instantiatingPclZip, and returns a translatableWP_Error(unzip_file_missing_zlib) instead. - The check is exposed via a new
unzip_file_pclzip_zlib_availablefilter (mirroring the existingunzip_file_use_ziparchivefilter in the same file), which also makes the new behavior directly unit-testable without needing an actual zlib-less PHP build. - Left the vendored
class-pclzip.phpuntouched, since it's third-party library code.
Testing
- Added
test_should_return_wp_error_when_zlib_extension_is_unavailable()intests/phpunit/tests/filesystem/unzipFilePclzip.php, which forces the new filter tofalseand asserts aWP_Errorwith the new error code is returned. - Ran the full
filetest group, PHPCS, and PHPStan — all green. - This bug only reproduces on PHP builds lacking zlib, which practically all modern installs have, so it isn't reproducible via manual UI steps in this repo's local dev environment; the added/passing test is the verification path.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation, tests, and PR description. Reviewed by Igor Rozum.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
#10
@
2 weeks ago
- Milestone Future Release → 7.2
As noted above, the reported issue of trying to upload a non-zip file as a plugin was indeed fixed in r57388.
However, it appears that ZIP support in PHP is not enabled by default and has to be explicitly enabled by --with-zip configuration option (for ZipArchive extension) or --with-zlib[=DIR] (for Zlib extension), so while uncommon, it might technically be possible to encounter the issue when both extensions are missing, as mentioned in comment:2.
PR 13613 aims to improve UX for the latter case, moving to 7.2 for review.
#11
@
10 days ago
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/13613
Environment
- WordPress: 7.1.2 (before) / trunk with PR #13613 (after), both in WordPress Playground
- Browser: Google Chrome 153.0.8010.52
- OS: Linux
- Theme: Twenty Twenty-Five
- MU Plugins: a test-only helper that forces PclZip and reports zlib as unavailable (code below)
- Plugins: None
Steps taken
- Went to Plugins > Add New > Upload Plugin and uploaded a .txt file (not a zip).
- Added the MU plugin below, which forces PclZip (
unzip_file_use_ziparchive) and returns false from the newunzip_file_pclzip_zlib_availablefilter, to simulate a PHP build without zlib. - Uploaded a valid plugin zip.
- Repeated the same steps with the patch applied.
- ✅ Patch is solving the problem.
Results
- Non-zip upload, before and after the patch: "Only .zip archives may be uploaded." This confirms the original report was already fixed in r57388, as noted in comment:10.
- Valid zip with zlib reported as missing, before the patch: the plugin installed normally, because the filter does not exist yet and Playground has zlib, so the original fatal error could not be reproduced here.
- Valid zip with zlib reported as missing, with the patch: the upload screen showed "PHP does not have the zlib extension enabled, which is required to extract this archive." and a "Go to Plugin Installer" link, instead of a fatal error.
Expected result
When zlib is not available, PclZip extraction returns a translatable WP_Error that the upload screen displays, instead of stopping with an untranslated fatal error.
Screenshots/Screencast with results
Non-zip upload (same before and after):

Valid zip, zlib reported as missing, before patch:

Valid zip, zlib reported as missing, with patch:

Support Content
<?php // Test-only MU plugin: force PclZip and report zlib as unavailable. add_filter( 'unzip_file_use_ziparchive', '__return_false' ); add_filter( 'unzip_file_pclzip_zlib_available', '__return_false' );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
A non-zip currently errors out with the following message, which is pretty terrible, I agree.
The error outlined in the ticket here,
Abort class-pclzip.php : Missing zlib extensionsoccurs when the PHP installation is missing bothZipArchivesupport, and doesn't containgzopen()(ie. missing zlib extension, or that ubuntu bug #30213). In this case all update-related functionality doesn't work, and we don't appear to check support properly.