WordPress.org

Make WordPress Core

#52511 closed enhancement (duplicate)

PclZip throwing error for zero byte files in PHP 8

Reported by: arl1nd Owned by:
Milestone: Priority: normal
Severity: major Version:
Component: Filesystem API Keywords: needs-patch
Focuses: Cc:

Description

Hi there,

As you know, PHP 8 requires file size to be greater than 0 in order to read it. PclZip fails to create an archive when a zero byte file appears in a directory. I think you should fix this issue in:

wp-admin/includes/class-pclzip.php:2677

Change History (3)

#1 @knutsp
10 months ago

Can confirm this - in case PHP zip extension (ZipArchive class) is not loaded. This was a major turn off in an early attempt to upgrade to PHP 8 - later zip became available in my cPanel and "solved" this for me. I guess PclZip is a fallback for ZipArchive.

#2 @arl1nd
10 months ago

Thanks @knutsp

Yes that is correct, this happens only when ZipArchive is not available. I've solved this by changing the original code in class-pclzip.php from:

$v_content = @fread($v_file, $p_header['size']);

To:

$v_content = '';

if ( 0 < $p_header['size'] ) {
    $v_content = @fread($v_file, $p_header['size']);
}

It would be great if you can add this patch in core trac.

Thanks for fast response.

#3 @SergeyBiryukov
10 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome back to WordPress Trac!

Thanks for the report, we're already tracking this issue in #52018.

Note: See TracTickets for help on using tickets.