Make WordPress Core

Changeset 56428


Ignore:
Timestamp:
08/23/2023 01:29:51 PM (16 months ago)
Author:
audrasjb
Message:

Site Health: Correct the check for disk space available to safely perform updates.

If the available disk space exceeds the PHP_INT_MAX value, i.e. a 32-bit PHP version is in use with more than 2 GB free, the type casting to (int) could cause
an overflow, and the Site Health test would then erroneously report that there is not enough free space.

This commit removes the unnecessary type casting and uses the result from disk_free_space() directly.

Includes optimizing the logic to skip further checks if the available disk space could not be determined.

Follow-up to [55720].

Props mathsgrinds, Presskopp, rajinsharwar, SergeyBiryukov.
Reviewed by azaozz, audrasjb.
Merges [56401] to the 6.3 branch.
Fixes #59116.

Location:
branches/6.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-admin/includes/class-wp-site-health.php

    r56342 r56428  
    19441944        $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;
    19451945
    1946         $available_space = false !== $available_space
    1947             ? (int) $available_space
    1948             : 0;
    1949 
    19501946        $result = array(
    19511947            'label'       => __( 'Disk space available to safely perform updates' ),
     
    19641960        );
    19651961
    1966         if ( $available_space < 100 * MB_IN_BYTES ) {
    1967             $result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
     1962        if ( false === $available_space ) {
     1963            $result['description'] = __( 'Could not determine available disk space for updates.' );
    19681964            $result['status']      = 'recommended';
    1969         }
    1970 
    1971         if ( $available_space < 20 * MB_IN_BYTES ) {
     1965        } elseif ( $available_space < 20 * MB_IN_BYTES ) {
    19721966            $result['description'] = __( 'Available disk space is critically low, less than 20 MB available. Proceed with caution, updates may fail.' );
    19731967            $result['status']      = 'critical';
    1974         }
    1975 
    1976         if ( ! $available_space ) {
    1977             $result['description'] = __( 'Could not determine available disk space for updates.' );
     1968        } elseif ( $available_space < 100 * MB_IN_BYTES ) {
     1969            $result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
    19781970            $result['status']      = 'recommended';
    19791971        }
Note: See TracChangeset for help on using the changeset viewer.