diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 407ea05f75..96012baf9c 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -601,6 +601,8 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { if ( true !== $zopen ) return new WP_Error('incompatible_archive', __('Incompatible Archive.')); + $uncompressed_size = 0; + for ( $i = 0; $i < $z->numFiles; $i++ ) { if ( ! $info = $z->statIndex($i) ) return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) ); @@ -608,12 +610,18 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; + $uncompressed_size += $info['size']; + if ( '/' == substr($info['name'], -1) ) // directory $needed_dirs[] = $to . untrailingslashit($info['name']); else $needed_dirs[] = $to . untrailingslashit(dirname($info['name'])); } + $available_space = disk_free_space( WP_CONTENT_DIR ); + if ( ( $uncompressed_size * 1.2 ) > $available_space ) + 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' ) ); + $needed_dirs = array_unique($needed_dirs); foreach ( $needed_dirs as $dir ) { // Check the parent folders of the folders all exist within the creation array. @@ -693,14 +701,22 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { if ( 0 == count($archive_files) ) return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) ); + $uncompressed_size = 0; + // Determine any children directories needed (From within the archive) foreach ( $archive_files as $file ) { if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; + $uncompressed_size += $file['size']; + $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) ); } + $available_space = disk_free_space( WP_CONTENT_DIR ); + if ( ( $uncompressed_size * 1.2 ) > $available_space ) + 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' ) ); + $needed_dirs = array_unique($needed_dirs); foreach ( $needed_dirs as $dir ) { // Check the parent folders of the folders all exist within the creation array. diff --git a/wp-includes/version.php b/wp-includes/version.php index 1fb60bc6e8..72b65e0b66 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '3.7-beta2-25773'; +$wp_version = '3.7-beta2-25774'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.