Make WordPress Core

Changeset 51694


Ignore:
Timestamp:
08/30/2021 02:27:48 PM (3 years ago)
Author:
desrosj
Message:

Filesystem API: Make sure to only call fread() on non-empty files in PclZip::privAddFile().

This avoids a fatal error on PHP 8 caused by passing a zero value to fread() as the $length argument, which must be greater than zero.

This commit also amends the previous solution for similar issues elsewhere in the file to ensure consistent type for string values, instead of changing the type from string to bool when trying to read from an empty file.

Follow-up to [50355].

Props DavidAnderson, jrf, SergeyBiryukov.
Merges [51686] to the 5.8 branch.
Fixes #54036.

Location:
branches/5.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.8

  • branches/5.8/src/wp-admin/includes/class-pclzip.php

    r50355 r51694  
    26752675
    26762676        // ----- Read the file content
    2677         $v_content = @fread($v_file, $p_header['size']);
     2677        if ($p_header['size'] > 0) {
     2678          $v_content = @fread($v_file, $p_header['size']);
     2679        }
     2680        else {
     2681          $v_content = '';
     2682        }
    26782683
    26792684        // ----- Close the file
     
    38853890
    38863891            // ----- Read the compressed file in a buffer (one shot)
    3887             if ( $p_entry['compressed_size'] > 0 ) {
     3892            if ($p_entry['compressed_size'] > 0) {
    38883893              $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
    38893894            }
    38903895            else {
    3891               $v_buffer = false;
     3896              $v_buffer = '';
    38923897            }
    38933898
     
    41024107
    41034108          // ----- Read the file in a buffer (one shot)
    4104           if ( $p_entry['compressed_size'] > 0 ) {
     4109          if ($p_entry['compressed_size'] > 0) {
    41054110            $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
    41064111          }
    41074112          else {
    4108             $v_buffer = false;
     4113            $v_buffer = '';
    41094114          }
    41104115
     
    41164121
    41174122          // ----- Read the compressed file in a buffer (one shot)
    4118           if ( $p_entry['compressed_size'] > 0 ) {
     4123          if ($p_entry['compressed_size'] > 0) {
    41194124            $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
    41204125          }
    41214126          else {
    4122             $v_buffer = false;
     4127            $v_buffer = '';
    41234128          }
    41244129
     
    42254230
    42264231          // ----- Reading the file
    4227           if ( $p_entry['compressed_size'] > 0 ) {
     4232          if ($p_entry['compressed_size'] > 0) {
    42284233            $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
    42294234          }
    42304235          else {
    4231             $p_string = false;
     4236            $p_string = '';
    42324237          }
    42334238        }
     
    42354240
    42364241          // ----- Reading the file
    4237           if ( $p_entry['compressed_size'] > 0 ) {
     4242          if ($p_entry['compressed_size'] > 0) {
    42384243            $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
    42394244          }
    42404245          else {
    4241             $v_data = false;
     4246            $v_data = '';
    42424247          }
    42434248
Note: See TracChangeset for help on using the changeset viewer.