Skip to content

Commit af15140

Browse files
committed
Grouped Backports to the 5.0 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.0 branch. Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin, xknown. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@57405 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ef5c886 commit af15140

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
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
@@ -63,6 +63,30 @@ public function __construct( $form, $urlholder ) {
6363
if ( isset( $file['error'] ) )
6464
wp_die( $file['error'] );
6565

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

src/wp-admin/includes/schema.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,11 @@ function populate_options() {
552552
else
553553
$autoload = 'yes';
554554

555-
if ( is_array($value) )
556-
$value = serialize($value);
557555
if ( !empty($insert) )
558556
$insert .= ', ';
557+
558+
$value = maybe_serialize( sanitize_option( $option, $value ) );
559+
559560
$insert .= $wpdb->prepare( "(%s, %s, %s)", $option, $value, $autoload );
560561
}
561562

src/wp-admin/update.php

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

147147
check_admin_referer('plugin-upload');
148148

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

151155
$title = __('Upload Plugin');
@@ -249,6 +253,10 @@
249253

250254
check_admin_referer('theme-upload');
251255

256+
if ( isset( $_FILES['themezip']['name'] ) && ! str_ends_with( strtolower( $_FILES['themezip']['name'] ), '.zip' ) ) {
257+
wp_die( __( 'Only .zip archives may be uploaded.' ) );
258+
}
259+
252260
$file_upload = new File_Upload_Upgrader('themezip', 'package');
253261

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

0 commit comments

Comments
 (0)