Skip to content

Commit da97951

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

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,30 @@ public function __construct( $form, $urlholder ) {
26262626
if ( isset( $file['error'] ) )
26272627
wp_die( $file['error'] );
26282628

2629+
if ( 'pluginzip' === $form || 'themezip' === $form ) {
2630+
$archive_is_valid = false;
2631+
2632+
/** This filter is documented in wp-admin/includes/file.php */
2633+
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
2634+
$archive = new ZipArchive();
2635+
$archive_is_valid = $archive->open( $file['file'], ZIPARCHIVE::CHECKCONS );
2636+
2637+
if ( true === $archive_is_valid ) {
2638+
$archive->close();
2639+
}
2640+
} else {
2641+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
2642+
2643+
$archive = new PclZip( $file['file'] );
2644+
$archive_is_valid = is_array( $archive->properties() );
2645+
}
2646+
2647+
if ( true !== $archive_is_valid ) {
2648+
wp_delete_file( $file['file'] );
2649+
wp_die( __( 'Incompatible Archive.' ) );
2650+
}
2651+
}
2652+
26292653
$this->filename = $_FILES[$form]['name'];
26302654
$this->package = $file['file'];
26312655

src/wp-admin/includes/schema.php

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

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

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');
@@ -251,6 +255,10 @@
251255

252256
check_admin_referer('theme-upload');
253257

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

256264
wp_enqueue_script( 'customize-loader' );

0 commit comments

Comments
 (0)