@@ -227,18 +227,44 @@ function wp_cache_serve_cache_file() {
227227 if ( $ wp_cache_gzip_encoding ) {
228228 if ( file_exists ( $ file . '.gz ' ) ) {
229229 $ cachefiledata = file_get_contents ( $ file . '.gz ' );
230+
231+ if ( false === $ cachefiledata ) {
232+ wp_cache_debug ( 'The cached gzip file could not be read. Must generate a new one. ' );
233+ return false ;
234+ }
235+
230236 wp_cache_debug ( "Fetched gzip static page data from supercache file using PHP. File: $ file.gz " );
231237 } else {
232- $ cachefiledata = gzencode ( file_get_contents ( $ file ), 6 , FORCE_GZIP );
238+ $ cachefiledata = file_get_contents ( $ file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
239+
240+ if ( false === $ cachefiledata ) {
241+ wp_cache_debug ( 'The cached file could not be read. Must generate a new one. ' );
242+ return false ;
243+ }
244+
245+ $ cachefiledata = gzencode ( $ cachefiledata , 6 , FORCE_GZIP );
233246 wp_cache_debug ( "Fetched static page data from supercache file using PHP and gzipped it. File: $ file " );
234247 }
235248 } else {
236249 $ cachefiledata = file_get_contents ( $ file );
250+
251+ if ( false === $ cachefiledata ) {
252+ wp_cache_debug ( 'The cached file could not be read. Must generate a new one. ' );
253+ return false ;
254+ }
255+
237256 wp_cache_debug ( "Fetched static page data from supercache file using PHP. File: $ file " );
238257 }
239258 } else {
240259 // get dynamic data from filtered file
241- $ cachefiledata = do_cacheaction ( 'wpsc_cachedata ' , file_get_contents ( $ file ) );
260+ $ cachefiledata = file_get_contents ( $ file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
261+
262+ if ( false === $ cachefiledata ) {
263+ wp_cache_debug ( 'The cached file could not be read. Must generate a new one. ' );
264+ return false ;
265+ }
266+
267+ $ cachefiledata = do_cacheaction ( 'wpsc_cachedata ' , $ cachefiledata );
242268 if ( $ wp_cache_gzip_encoding ) {
243269 $ cachefiledata = gzencode ( $ cachefiledata , 6 , FORCE_GZIP );
244270 wp_cache_debug ( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $ file " );
@@ -301,6 +327,7 @@ function wp_cache_serve_cache_file() {
301327 }
302328 header ( 'Last-Modified: ' . $ local_mod_time );
303329 }
330+
304331 echo $ cachefiledata ;
305332 exit ();
306333 } else {
0 commit comments