Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pclzip and zero length files in PHP 8.x #258

Open
Jako opened this issue Oct 18, 2024 · 9 comments
Open

pclzip and zero length files in PHP 8.x #258

Jako opened this issue Oct 18, 2024 · 9 comments

Comments

@Jako
Copy link
Collaborator

Jako commented Oct 18, 2024

xPDO 2.x has issues with zero length files in PHP 8.x. The same code works fine in PHP 7.x. The same issue may occur with xPDO 3.x.

PHP Fatal error:  Uncaught ValueError: fread(): Argument #2 ($length) must be greater than 0 in /…/core/xpdo/compression/pclzip.lib.php:2678

I am not sure why this issue occurs only in PHP 8.x, but creating a transport file with PHP 7.4 works well and not with PHP 8.1/8.2 during my tests when an empty file (.gitignore in my case) exists in a folder in a package. If the file has a length of 1 byte everything works well.

It is more of a guide as to why the issue is occurring and how it can be resolved.

@opengeek
Copy link
Member

Why are you using pclzip with PHP 8? Do you have hosting that does not include the zip extension?

@opengeek
Copy link
Member

Point being, I'd really love to get rid of the pclzip code.

@Jako
Copy link
Collaborator Author

Jako commented Oct 18, 2024

I am using MAMP locally. For whatever reason this does not use the zip extension.

@Jako
Copy link
Collaborator Author

Jako commented Oct 18, 2024

I can install the extension with https://documentation.mamp.info/en/MAMP-PRO-Mac/FAQ/PHP/Install-a-PHP-extension-using-PECL/ but this has to be done for AFAIK every different PHP version.

@opengeek
Copy link
Member

Right. The problem is there is no PCLZIP version maintained any longer and it is not compatible with PHP 8. I have no interest in maintaining yet another project.

@Jako
Copy link
Collaborator Author

Jako commented Oct 18, 2024

Before you drop it, PCLZIP currently only has issues with empty files in PHP 8.x in MODX.

@Jako
Copy link
Collaborator Author

Jako commented Oct 18, 2024

Just to be sure. MAMP is compiled with ZIP support. Does it have to use PCLZIP then? Or is it just a wrong check that xPDO uses that part of code?

@corrosive4354
Copy link

I am using MAMP locally. For whatever reason this does not use the zip extension.

maybe u can use Servbay instead of MAMP to deploy. Servbay can install the packages you need and eliminate environment bugs

@corrosive4354
Copy link

Check file length: Before calling fread(), check if the file length is greater than 0. If the file length is 0, you can choose to skip reading the file or process it as a specific logic.

Sample code:

$filePath = 'path/to/your/file';

if (filesize($filePath) > 0) {
$handle = fopen($filePath, 'rb');
$content = fread($handle, filesize($filePath));
fclose($handle);
} else {
// Logic for handling zero-length files

In addition, if you need to convert between PHP7.X and PHP8.X, you can use the Servbay tool to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants