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.
Built from https://develop.svn.wordpress.org/branches/5.8@51694


git-svn-id: http://core.svn.wordpress.org/branches/5.8@51300 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2021-08-30 14:28:57 +00:00
parent ccb796fb1e
commit bbda256d9c
2 changed files with 17 additions and 12 deletions

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

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8.1-alpha-51691';
$wp_version = '5.8.1-alpha-51694';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.