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.
Fixes #54036.
Built from https://develop.svn.wordpress.org/trunk@51686


git-svn-id: http://core.svn.wordpress.org/trunk@51292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-08-29 01:33:58 +00:00
parent b441808aee
commit 26a276db6f
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.9-alpha-51685';
$wp_version = '5.9-alpha-51686';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.