WordPress.org

Make WordPress Core

Changeset 25774


Ignore:
Timestamp:
10/14/2013 08:14:13 PM (6 years ago)
Author:
nacin
Message:

In unzip_file(), confirm we have enough available disk space before extracting.

"enough" is calculated by adding up the uncompressed size of the files in the archive, then adding a 20% buffer.

props dd32.
fixes #25576.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r25763 r25774  
    602602        return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
    603603
     604    $uncompressed_size = 0;
     605
    604606    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    605607        if ( ! $info = $z->statIndex($i) )
     
    608610        if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
    609611            continue;
     612
     613        $uncompressed_size += $info['size'];
    610614
    611615        if ( '/' == substr($info['name'], -1) ) // directory
     
    614618            $needed_dirs[] = $to . untrailingslashit(dirname($info['name']));
    615619    }
     620
     621    $available_space = disk_free_space( WP_CONTENT_DIR );
     622    if ( ( $uncompressed_size * 1.2 ) > $available_space )
     623        return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) );
    616624
    617625    $needed_dirs = array_unique($needed_dirs);
     
    694702        return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
    695703
     704    $uncompressed_size = 0;
     705
    696706    // Determine any children directories needed (From within the archive)
    697707    foreach ( $archive_files as $file ) {
     
    699709            continue;
    700710
     711        $uncompressed_size += $file['size'];
     712
    701713        $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) );
    702714    }
     715
     716    $available_space = disk_free_space( WP_CONTENT_DIR );
     717    if ( ( $uncompressed_size * 1.2 ) > $available_space )
     718        return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) );
    703719
    704720    $needed_dirs = array_unique($needed_dirs);
  • trunk/src/wp-includes/version.php

    r25773 r25774  
    55 * @global string $wp_version
    66 */
    7 $wp_version = '3.7-beta2-25773-src';
     7$wp_version = '3.7-beta2-25774-src';
    88
    99/**
Note: See TracChangeset for help on using the changeset viewer.