Make WordPress Core


Ignore:
Timestamp:
09/27/2023 04:29:37 PM (13 months ago)
Author:
costdev
Message:

Filesystem API: Free the archive in _unzip_file_ziparchive().

There are several early returns in _unzip_file_ziparchive() which don't close the archive prior to returning.

As this function is used in installation and upgrade processes which are memory-intensive, this calls ZipArchive::close() to free the archive prior to each early return. This excludes the first return which is a result of a failure to open the archive, which is freed internally when the failure occurs.

References:

Follow-up to: [13005], [13006], [13015], [13221], [14346] [25779].

Props azaozz, afragen, joemcgill, costdev.
Fixes #59467

File:
1 edited

Legend:

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

    r56689 r56735  
    16731673
    16741674        if ( ! $info ) {
     1675            $z->close();
    16751676            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    16761677        }
     
    17101711
    17111712        if ( $available_space && ( $required_space > $available_space ) ) {
     1713            $z->close();
    17121714            return new WP_Error(
    17131715                'disk_full_unzip_file',
     
    17471749        // Only check to see if the Dir exists upon creation failure. Less I/O this way.
    17481750        if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) {
     1751            $z->close();
    17491752            return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), $_dir );
    17501753        }
     
    17751778
    17761779        if ( ! $info ) {
     1780            $z->close();
    17771781            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    17781782        }
     
    17941798
    17951799        if ( false === $contents ) {
     1800            $z->close();
    17961801            return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );
    17971802        }
    17981803
    17991804        if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE ) ) {
     1805            $z->close();
    18001806            return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'] );
    18011807        }
Note: See TracChangeset for help on using the changeset viewer.