WordPress.org

Make WordPress Core

Ticket #33053: class-wp-upgrader.php.patch

File class-wp-upgrader.php.patch, 2.4 KB (added by liegeandlief, 5 years ago)

class-wp-upgrader.php altered to prevent unzip working direcotry path from being too long

  • class-wp-upgrader.php

     
    139139                $this->strings['no_files'] = __('The package contains no files.');
    140140                $this->strings['folder_exists'] = __('Destination folder already exists.');
    141141                $this->strings['mkdir_failed'] = __('Could not create directory.');
     142                $this->strings['working_dir_filepath_too_long'] = __('Working directory path length is too long.');
    142143                $this->strings['incompatible_archive'] = __('The package could not be installed.');
    143144                $this->strings['files_not_writable'] = __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' );
    144145
     
    280281                                $wp_filesystem->delete($upgrade_folder . $file['name'], true);
    281282                }
    282283
    283                 // We need a working directory - Strip off any .tmp or .zip suffixes
    284                 $working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
     284                //Strip off any .tmp or .zip suffixes from temporary package filename
     285                $tmp_filename_no_suffix = basename( basename( $package, '.tmp' ), '.zip' );
    285286
     287                // We need a working directory
     288                $working_dir = $upgrade_folder . $tmp_filename_no_suffix;
     289               
     290                /* Filepaths should be 255 characters or fewer to prevent errors.
     291                If working directory path is longer than 255 characters then try to remove some
     292                characters from the temporary directory name to bring it within 255 characters. */
     293                $how_much_too_long = strlen($working_dir)-255;
     294               
     295                if ($how_much_too_long > 0) {
     296                        $tmp_filename_no_suffix_length = strlen($tmp_filename_no_suffix);
     297                        /* If the length by which the working directory filepath is too long is greater
     298                        than or equal to the length of the temporary directory's name then throw an error
     299                        as we will not be able to create a short enough working directory path. */
     300                        if ($how_much_too_long >= $tmp_filename_no_suffix_length) {
     301                                return new WP_Error( 'working_dir_filepath_too_long', $this->strings['working_dir_filepath_too_long'] );
     302                        }
     303                        $shortened_directory_name = substr($tmp_filename_no_suffix, 0, $tmp_filename_no_suffix_length-$how_much_too_long);
     304                        $working_dir = $upgrade_folder . $shortened_directory_name;
     305                }
     306
    286307                // Clean up working directory
    287308                if ( $wp_filesystem->is_dir($working_dir) )
    288309                        $wp_filesystem->delete($working_dir, true);