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.

Built from https://develop.svn.wordpress.org/trunk@25774


git-svn-id: http://core.svn.wordpress.org/trunk@25687 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-10-14 20:15:09 +00:00
parent 31cf7e9d80
commit d68a80217f
2 changed files with 17 additions and 1 deletions

View File

@ -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.

View File

@ -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.