From cc30c42d72c4f72d9fef261c890818693466afd5 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 30 Jan 2024 14:52:00 +0000 Subject: [PATCH] Grouped Backports to the 5.6 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.6 branch. Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin, xknown. Built from https://develop.svn.wordpress.org/branches/5.6@57399 git-svn-id: http://core.svn.wordpress.org/branches/5.6@56905 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-file-upload-upgrader.php | 24 +++++++++++++++++++ wp-admin/includes/schema.php | 6 ++--- wp-admin/update.php | 8 +++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/class-file-upload-upgrader.php b/wp-admin/includes/class-file-upload-upgrader.php index 3bdae332c8..f9991c27b1 100644 --- a/wp-admin/includes/class-file-upload-upgrader.php +++ b/wp-admin/includes/class-file-upload-upgrader.php @@ -68,6 +68,30 @@ class File_Upload_Upgrader { wp_die( $file['error'] ); } + if ( 'pluginzip' === $form || 'themezip' === $form ) { + $archive_is_valid = false; + + /** This filter is documented in wp-admin/includes/file.php */ + if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) { + $archive = new ZipArchive(); + $archive_is_valid = $archive->open( $file['file'], ZIPARCHIVE::CHECKCONS ); + + if ( true === $archive_is_valid ) { + $archive->close(); + } + } else { + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; + + $archive = new PclZip( $file['file'] ); + $archive_is_valid = is_array( $archive->properties() ); + } + + if ( true !== $archive_is_valid ) { + wp_delete_file( $file['file'] ); + wp_die( __( 'Incompatible Archive.' ) ); + } + } + $this->filename = $_FILES[ $form ]['name']; $this->package = $file['file']; diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index a59c7c36ce..dbd76642a0 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -584,14 +584,12 @@ function populate_options( array $options = array() ) { $autoload = 'yes'; } - if ( is_array( $value ) ) { - $value = serialize( $value ); - } - if ( ! empty( $insert ) ) { $insert .= ', '; } + $value = maybe_serialize( sanitize_option( $option, $value ) ); + $insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload ); } diff --git a/wp-admin/update.php b/wp-admin/update.php index 7980ea7a8b..898de05309 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -151,6 +151,10 @@ if ( isset( $_GET['action'] ) ) { check_admin_referer( 'plugin-upload' ); + if ( isset( $_FILES['pluginzip']['name'] ) && ! str_ends_with( strtolower( $_FILES['pluginzip']['name'] ), '.zip' ) ) { + wp_die( __( 'Only .zip archives may be uploaded.' ) ); + } + $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' ); $title = __( 'Upload Plugin' ); @@ -293,6 +297,10 @@ if ( isset( $_GET['action'] ) ) { check_admin_referer( 'theme-upload' ); + if ( isset( $_FILES['themezip']['name'] ) && ! str_ends_with( strtolower( $_FILES['themezip']['name'] ), '.zip' ) ) { + wp_die( __( 'Only .zip archives may be uploaded.' ) ); + } + $file_upload = new File_Upload_Upgrader( 'themezip', 'package' ); $title = __( 'Upload Theme' );