Make WordPress Core

Changeset 50355


Ignore:
Timestamp:
02/16/2021 06:40:29 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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

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.

Props yakimun, fierevere, jrf, DavidAnderson, SergeyBiryukov.
Fixes #52018.

File:
1 edited

Legend:

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

    r49194 r50355  
    38853885
    38863886            // ----- Read the compressed file in a buffer (one shot)
    3887             $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     3887            if ( $p_entry['compressed_size'] > 0 ) {
     3888              $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     3889            }
     3890            else {
     3891              $v_buffer = false;
     3892            }
    38883893
    38893894            // ----- Decompress the file
     
    40974102
    40984103          // ----- Read the file in a buffer (one shot)
    4099           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     4104          if ( $p_entry['compressed_size'] > 0 ) {
     4105            $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     4106          }
     4107          else {
     4108            $v_buffer = false;
     4109          }
    41004110
    41014111          // ----- Send the file to the output
     
    41064116
    41074117          // ----- Read the compressed file in a buffer (one shot)
    4108           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     4118          if ( $p_entry['compressed_size'] > 0 ) {
     4119            $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
     4120          }
     4121          else {
     4122            $v_buffer = false;
     4123          }
    41094124
    41104125          // ----- Decompress the file
     
    42104225
    42114226          // ----- Reading the file
    4212           $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
     4227          if ( $p_entry['compressed_size'] > 0 ) {
     4228            $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
     4229          }
     4230          else {
     4231            $p_string = false;
     4232          }
    42134233        }
    42144234        else {
    42154235
    42164236          // ----- Reading the file
    4217           $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
     4237          if ( $p_entry['compressed_size'] > 0 ) {
     4238            $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
     4239          }
     4240          else {
     4241            $v_data = false;
     4242          }
    42184243
    42194244          // ----- Decompress the file
Note: See TracChangeset for help on using the changeset viewer.