Code Modernization: Check if the file to retrieve metadata from in `get_file_data()` was successfully opened.

This avoids a fatal error on PHP 8 caused by passing a `false` value to `fread()`, instead of a file resource.

See #50913.
Built from https://develop.svn.wordpress.org/trunk@49073


git-svn-id: http://core.svn.wordpress.org/trunk@48835 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-09-30 12:20:03 +00:00
parent e43ff0e991
commit bdccfa3a03
2 changed files with 9 additions and 5 deletions

View File

@ -6040,11 +6040,15 @@ function get_file_data( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading. // We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' ); $fp = fopen( $file, 'r' );
// Pull only the first 8 KB of the file in. if ( $fp ) {
$file_data = fread( $fp, 8 * KB_IN_BYTES ); // Pull only the first 8 KB of the file in.
$file_data = fread( $fp, 8 * KB_IN_BYTES );
// PHP will close file handle, but we are good citizens. // PHP will close file handle, but we are good citizens.
fclose( $fp ); fclose( $fp );
} else {
$file_data = '';
}
// Make sure we catch CR-only line endings. // Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data ); $file_data = str_replace( "\r", "\n", $file_data );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-alpha-49072'; $wp_version = '5.6-alpha-49073';
/** /**
* 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.