From b8efab15d881506602968ff45605dc471feef5b8 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 14 Oct 2013 20:57:28 +0000 Subject: [PATCH] Account for possible failures by disk_free_space(), as well as the potential need to copy the unzipped files. see #25576. git-svn-id: https://develop.svn.wordpress.org/trunk@25776 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 96012baf9c..8607b98ce7 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -618,8 +618,13 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { $needed_dirs[] = $to . untrailingslashit(dirname($info['name'])); } + /* + * disk_free_space() could return false. Assume that any falsey value is an error. + * A disk that has zero free bytes has bigger problems. + * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. + */ $available_space = disk_free_space( WP_CONTENT_DIR ); - if ( ( $uncompressed_size * 1.2 ) > $available_space ) + if ( $available_space && ( $uncompressed_size * 2.1 ) > $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); @@ -713,8 +718,13 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) ); } + /* + * disk_free_space() could return false. Assume that any falsey value is an error. + * A disk that has zero free bytes has bigger problems. + * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. + */ $available_space = disk_free_space( WP_CONTENT_DIR ); - if ( ( $uncompressed_size * 1.2 ) > $available_space ) + if ( $available_space && ( $uncompressed_size * 2.1 ) > $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);