Make WordPress Core


Ignore:
Timestamp:
08/17/2023 11:16:08 AM (16 months ago)
Author:
SergeyBiryukov
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.
Fixes #59116.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r56341 r56401  
    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.