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. git-svn-id: https://develop.svn.wordpress.org/trunk@25774 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ddf6da1d8c
commit
5db3863d12
@ -601,6 +601,8 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
|
|||||||
if ( true !== $zopen )
|
if ( true !== $zopen )
|
||||||
return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
|
return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
|
||||||
|
|
||||||
|
$uncompressed_size = 0;
|
||||||
|
|
||||||
for ( $i = 0; $i < $z->numFiles; $i++ ) {
|
for ( $i = 0; $i < $z->numFiles; $i++ ) {
|
||||||
if ( ! $info = $z->statIndex($i) )
|
if ( ! $info = $z->statIndex($i) )
|
||||||
return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
|
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
|
if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
$uncompressed_size += $info['size'];
|
||||||
|
|
||||||
if ( '/' == substr($info['name'], -1) ) // directory
|
if ( '/' == substr($info['name'], -1) ) // directory
|
||||||
$needed_dirs[] = $to . untrailingslashit($info['name']);
|
$needed_dirs[] = $to . untrailingslashit($info['name']);
|
||||||
else
|
else
|
||||||
$needed_dirs[] = $to . untrailingslashit(dirname($info['name']));
|
$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);
|
$needed_dirs = array_unique($needed_dirs);
|
||||||
foreach ( $needed_dirs as $dir ) {
|
foreach ( $needed_dirs as $dir ) {
|
||||||
// Check the parent folders of the folders all exist within the creation array.
|
// 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) )
|
if ( 0 == count($archive_files) )
|
||||||
return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
|
return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
|
||||||
|
|
||||||
|
$uncompressed_size = 0;
|
||||||
|
|
||||||
// Determine any children directories needed (From within the archive)
|
// Determine any children directories needed (From within the archive)
|
||||||
foreach ( $archive_files as $file ) {
|
foreach ( $archive_files as $file ) {
|
||||||
if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory
|
if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
$uncompressed_size += $file['size'];
|
||||||
|
|
||||||
$needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) );
|
$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);
|
$needed_dirs = array_unique($needed_dirs);
|
||||||
foreach ( $needed_dirs as $dir ) {
|
foreach ( $needed_dirs as $dir ) {
|
||||||
// Check the parent folders of the folders all exist within the creation array.
|
// Check the parent folders of the folders all exist within the creation array.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '3.7-beta2-25773-src';
|
$wp_version = '3.7-beta2-25774-src';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user