Skip to content

Commit 6f02127

Browse files
committed
Upload: Fallback to PclZip to validate ZIP file uploads.
ZipArchive can fail to validate ZIP files correctly and report valid files as invalid. This introduces a fallback to PclZip to check validity of files if ZipArchive fails them. This introduces the new function wp_zip_file_is_valid() to validate archives. Follow up to [57388]. Reviewed by jorbin. Merges [57537] to the 6.4 branch. Props audunmb, azaozz, britner, cdevroe, colorful-tones, costdev, courane01, endymion00, feastdesignco, halounsbury, jeffpaul, johnbillion, jorbin, jsandtro, karinclimber, kevincoleman, koesper, maartenbelmans, mathewemoore, melcarthus, mujuonly, nerdpressteam, olegfuture, otto42, peterwilsoncc, room34, sayful, schutzsmith, stephencronin, svitlana41319, swissspidy, tnolte, tobiasbg, vikram6, welaunchio. Fixes #60398. git-svn-id: https://develop.svn.wordpress.org/branches/6.4@57929 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 02fb534 commit 6f02127

17 files changed

+147
-18
lines changed

src/wp-admin/includes/class-file-upload-upgrader.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,7 @@ public function __construct( $form, $urlholder ) {
7070
}
7171

7272
if ( 'pluginzip' === $form || 'themezip' === $form ) {
73-
$archive_is_valid = false;
74-
75-
/** This filter is documented in wp-admin/includes/file.php */
76-
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
77-
$archive = new ZipArchive();
78-
$archive_is_valid = $archive->open( $file['file'], ZIPARCHIVE::CHECKCONS );
79-
80-
if ( true === $archive_is_valid ) {
81-
$archive->close();
82-
}
83-
} else {
84-
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
85-
86-
$archive = new PclZip( $file['file'] );
87-
$archive_is_valid = is_array( $archive->properties() );
88-
}
89-
90-
if ( true !== $archive_is_valid ) {
73+
if ( ! wp_zip_file_is_valid( $file['file'] ) ) {
9174
wp_delete_file( $file['file'] );
9275
wp_die( __( 'Incompatible Archive.' ) );
9376
}

src/wp-admin/includes/file.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,37 @@ function wp_trusted_keys() {
15631563
return apply_filters( 'wp_trusted_keys', $trusted_keys );
15641564
}
15651565

1566+
/**
1567+
* Determines whether the given file is a valid ZIP file.
1568+
*
1569+
* This function does not test to ensure that a file exists. Non-existent files
1570+
* are not valid ZIPs, so those will also return false.
1571+
*
1572+
* @since 6.4.4
1573+
*
1574+
* @param string $file Full path to the ZIP file.
1575+
* @return bool Whether the file is a valid ZIP file.
1576+
*/
1577+
function wp_zip_file_is_valid( $file ) {
1578+
/** This filter is documented in wp-admin/includes/file.php */
1579+
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
1580+
$archive = new ZipArchive();
1581+
$archive_is_valid = $archive->open( $file, ZipArchive::CHECKCONS );
1582+
if ( true === $archive_is_valid ) {
1583+
$archive->close();
1584+
return true;
1585+
}
1586+
}
1587+
1588+
// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
1589+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
1590+
1591+
$archive = new PclZip( $file );
1592+
$archive_is_valid = is_array( $archive->properties() );
1593+
1594+
return $archive_is_valid;
1595+
}
1596+
15661597
/**
15671598
* Unzips a specified ZIP file to a location on the filesystem via the WordPress
15681599
* Filesystem Abstraction.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
The following files were sourced from https://github.com/ZJONSSON/node-unzipper a fork of https://github.com/EvanOxfeld/node-unzip
2+
3+
* archive-comment.zip
4+
* archive-cp866.zip
5+
* archive-directory-entry.zip
6+
* archive-encrypted.zip
7+
* archive-flags-set.zip
8+
* archive-invalid.zip
9+
* archive-large.zip
10+
* archive-uncompressed.zip
11+
* archive.crx
12+
13+
Copyright (c) 2012 - 2013 Near Infinity Corporation
14+
Copyright (c) 2016 - 2024 Ziggy Jonsson ([email protected])
15+
16+
Permission is hereby granted, free of charge, to any person obtaining
17+
a copy of this software and associated documentation files (the
18+
"Software"), to deal in the Software without restriction, including
19+
without limitation the rights to use, copy, modify, merge, publish,
20+
distribute, sublicense, and/or sell copies of the Software, and to
21+
permit persons to whom the Software is furnished to do so, subject to
22+
the following conditions:
23+
24+
The above copyright notice and this permission notice shall be
25+
included in all copies or substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
468 Bytes
Binary file not shown.
163 Bytes
Binary file not shown.
2.42 KB
Binary file not shown.
1.65 KB
Binary file not shown.
1.6 KB
Binary file not shown.
1.17 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Shucked
2+
3+
Shucked is a 2022 musical with music and lyrics by Brandy Clark and Shane McAnally, and a book by Robert Horn. The Broadway production began previews at the Nederlander Theatre on March 8, 2023, before opening on April 4. The show received positive reviews and went on to receive nine nominations at the 76th Tony Awards, including Best Musical. Cast member Alex Newell became one of the first two openly non-binary performers to be nominated for and win a Tony Award, with their win for Best Featured Actor in a Musical.
4+
5+
A U.S. tour, West End production, and feature film adaptation are currently planned.
6+
7+
From Wikipedia (https://en.wikipedia.org/wiki/Shucked) under Creative Commons Attribution CC-BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)

0 commit comments

Comments
 (0)