Make WordPress Core

Changeset 13006


Ignore:
Timestamp:
02/07/2010 05:02:24 AM (15 years ago)
Author:
dd32
Message:

Better error checking for ZipArchive extraction. See #10403

File:
1 edited

Legend:

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

    r13005 r13006  
    539539
    540540    $z = new ZipArchive();
    541     if ( ! $z->open($file) )
     541    if ( true !== $z->open($file, ZIPARCHIVE::CHECKCONS) )
    542542        return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
    543543
    544544    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    545545        if ( ! $info = $z->statIndex($i) )
    546             return new WP_Error('stat_failure', __('Could not retrieve file from archive.'));
     546            return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
    547547
    548548        if ( '/' == substr($info['name'], -1) ) // directory
     
    564564    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    565565        if ( ! $info = $z->statIndex($i) )
    566             return new WP_Error('stat_failure', __('Could not retrieve file from archive.'));
     566            return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
    567567
    568568        if ( '/' == substr($info['name'], -1) ) // directory
    569569            continue;
    570570
    571         if ( ! $wp_filesystem->put_contents( $to . $info['name'], $z->getFromIndex($i), FS_CHMOD_FILE) )
     571        $contents = $z->getFromIndex($i);
     572        if ( false === $contents )
     573            return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
     574
     575        if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
    572576            return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
    573577    }
Note: See TracChangeset for help on using the changeset viewer.