Skip to content

Commit 84a564e

Browse files
committed
Grouped Backports to the 5.3 branch
- Install: When populating options, maybe_serialize instead of always serialize. - Uploads: Check for and verify ZIP archives. Merges [57388] and [57389] to the 5.3 branch. Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin, xknown. git-svn-id: https://develop.svn.wordpress.org/branches/5.3@57402 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 43d8a5a commit 84a564e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ public function __construct( $form, $urlholder ) {
6868
wp_die( $file['error'] );
6969
}
7070

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

src/wp-admin/includes/schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ function populate_options( array $options = array() ) {
573573
$autoload = 'yes';
574574
}
575575

576-
if ( is_array( $value ) ) {
577-
$value = serialize( $value );
578-
}
579576
if ( ! empty( $insert ) ) {
580577
$insert .= ', ';
581578
}
579+
580+
$value = maybe_serialize( sanitize_option( $option, $value ) );
581+
582582
$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
583583
}
584584

src/wp-admin/update.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147

148148
check_admin_referer( 'plugin-upload' );
149149

150+
if ( isset( $_FILES['pluginzip']['name'] ) && ! str_ends_with( strtolower( $_FILES['pluginzip']['name'] ), '.zip' ) ) {
151+
wp_die( __( 'Only .zip archives may be uploaded.' ) );
152+
}
153+
150154
$file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
151155

152156
$title = __( 'Upload Plugin' );
@@ -266,6 +270,10 @@
266270

267271
check_admin_referer( 'theme-upload' );
268272

273+
if ( isset( $_FILES['themezip']['name'] ) && ! str_ends_with( strtolower( $_FILES['themezip']['name'] ), '.zip' ) ) {
274+
wp_die( __( 'Only .zip archives may be uploaded.' ) );
275+
}
276+
269277
$file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
270278

271279
$title = __( 'Upload Theme' );

0 commit comments

Comments
 (0)