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.

git-svn-id: https://develop.svn.wordpress.org/branches/5.8@51694 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-08-30 14:27:48 +00:00
parent 9d36011c0c
commit bb7645ddb9

View File

@ -2674,7 +2674,12 @@
}
// ----- Read the file content
$v_content = @fread($v_file, $p_header['size']);
if ($p_header['size'] > 0) {
$v_content = @fread($v_file, $p_header['size']);
}
else {
$v_content = '';
}
// ----- Close the file
@fclose($v_file);
@ -3884,11 +3889,11 @@
// ----- Read the compressed file in a buffer (one shot)
if ( $p_entry['compressed_size'] > 0 ) {
if ($p_entry['compressed_size'] > 0) {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else {
$v_buffer = false;
$v_buffer = '';
}
// ----- Decompress the file
@ -4101,11 +4106,11 @@
if ($p_entry['compressed_size'] == $p_entry['size']) {
// ----- Read the file in a buffer (one shot)
if ( $p_entry['compressed_size'] > 0 ) {
if ($p_entry['compressed_size'] > 0) {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else {
$v_buffer = false;
$v_buffer = '';
}
// ----- Send the file to the output
@ -4115,11 +4120,11 @@
else {
// ----- Read the compressed file in a buffer (one shot)
if ( $p_entry['compressed_size'] > 0 ) {
if ($p_entry['compressed_size'] > 0) {
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else {
$v_buffer = false;
$v_buffer = '';
}
// ----- Decompress the file
@ -4224,21 +4229,21 @@
if ($p_entry['compression'] == 0) {
// ----- Reading the file
if ( $p_entry['compressed_size'] > 0 ) {
if ($p_entry['compressed_size'] > 0) {
$p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else {
$p_string = false;
$p_string = '';
}
}
else {
// ----- Reading the file
if ( $p_entry['compressed_size'] > 0 ) {
if ($p_entry['compressed_size'] > 0) {
$v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
}
else {
$v_data = false;
$v_data = '';
}
// ----- Decompress the file