Make WordPress Core

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)

Screenshot (175).png​ (13.8 KB ) - added by sawf1y 3 weeks ago.
30963-nonzip-after.png​ (4.3 KB ) - added by rahultank 10 days ago.
Non-zip upload message
30963-before.png​ (15.8 KB ) - added by rahultank 10 days ago.
Valid zip with zlib reported missing, before patch
30963-after.png​ (15.2 KB ) - added by rahultank 10 days ago.
Valid zip with zlib reported missing, with patch (PR 13613)

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
12 years ago

  • Component Administration → Plugins
  • Focuses administration added

#2 follow-up: @dd32
12 years ago

A non-zip currently errors out with the following message, which is pretty terrible, I agree.

The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

The error outlined in the ticket here, Abort class-pclzip.php : Missing zlib extensions occurs when the PHP installation is missing both ZipArchive support, and doesn't contain gzopen() (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.

#3 in reply to: ↑ 2 @dd32
12 years ago

Replying to dd32:

The error outlined in the ticket here, Abort class-pclzip.php : Missing zlib extensions occurs when the PHP installation is missing both ZipArchive support, and doesn't contain gzopen() (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 @DrewAPicture
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.

#5 @earnjam
6 years ago

  • Milestone Awaiting Review → Future Release
  • Version 4.1

#6 @sawf1y
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 @sawf1y
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 @sawf1y
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() in src/wp-admin/includes/file.php that detects the missing zlib extension before ever instantiating PclZip, and returns a translatable WP_Error (unzip_file_missing_zlib) instead.
  • The check is exposed via a new unzip_file_pclzip_zlib_available filter (mirroring the existing unzip_file_use_ziparchive filter 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.php untouched, since it's third-party library code.

Testing

  • Added test_should_return_wp_error_when_zlib_extension_is_unavailable() in tests/phpunit/tests/filesystem/unzipFilePclzip.php, which forces the new filter to false and asserts a WP_Error with the new error code is returned.
  • Ran the full file test 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 @SergeyBiryukov
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.

@rahultank
10 days ago

Non-zip upload message

@rahultank
10 days ago

Valid zip with zlib reported missing, before patch

@rahultank
10 days ago

Valid zip with zlib reported missing, with patch (PR 13613)

#11 @rahultank
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

  1. Went to Plugins > Add New > Upload Plugin and uploaded a .txt file (not a zip).
  2. Added the MU plugin below, which forces PclZip (unzip_file_use_ziparchive) and returns false from the new unzip_file_pclzip_zlib_available filter, to simulate a PHP build without zlib.
  3. Uploaded a valid plugin zip.
  4. Repeated the same steps with the patch applied.
  5. ✅ 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):
Non-zip upload message

Valid zip, zlib reported as missing, before patch:
Valid zip with zlib reported missing, before patch

Valid zip, zlib reported as missing, with patch:
Valid zip with zlib reported missing, with patch (PR 13613)

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' );
Note: See TracTickets for help on using tickets.