From d75f08eb824653b79a506f7821834ee9aff5917a Mon Sep 17 00:00:00 2001
From: Max Kellermann <mk@cm4all.com>
Date: Fri, 4 Feb 2022 16:36:21 +0100
Subject: [PATCH 3/5] functions.php: use file_get_contents() in get_file_data()

---
 src/wp-includes/functions.php | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 667049aa3f..f0349490f1 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -6528,16 +6528,10 @@ function wp_scheduled_delete() {
  * @return string[] Array of file header values keyed by header name.
  */
 function get_file_data( $file, $default_headers, $context = '' ) {
-	// We don't need to write to the file, so just open for reading.
-	$fp = fopen( $file, 'r' );
+	// Pull only the first 8 KB of the file in.
+	$file_data = file_get_contents( $file, false, null, 0, 8192 );
 
-	if ( $fp ) {
-		// 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.
-		fclose( $fp );
-	} else {
+	if ($file_data === false ) {
 		$file_data = '';
 	}
 
-- 
2.34.0

