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

.zip to .zip.cpgz infinite loop on mac #27

Closed
ArturGrigio opened this Issue Jan 28, 2015 · 17 comments

Comments

Projects
None yet
6 participants
@ArturGrigio

ArturGrigio commented Jan 28, 2015

On a mac, the downloaded zip enters into a .zip to .zip.cpgz infinite loop (apparently OSX creates the .cpgz to read what's inside the .zip, but it fails and it creates a .zip and so on...).

I believe it's got something to do with the headers.

Can someone please look into this?

@donatj

This comment has been minimized.

Show comment
Hide comment
@donatj

donatj Jan 28, 2015

Collaborator

What version of the library are you using (If you could get the git sha1 that'd be awesome)?
What version of PHP?
What version of OS X?
Any other info you could throw this way to help us track it down? Are you using composer?

I work exclusively on Mac (I'm one of the devs) and haven't seen this issue.

Collaborator

donatj commented Jan 28, 2015

What version of the library are you using (If you could get the git sha1 that'd be awesome)?
What version of PHP?
What version of OS X?
Any other info you could throw this way to help us track it down? Are you using composer?

I work exclusively on Mac (I'm one of the devs) and haven't seen this issue.

@donatj

This comment has been minimized.

Show comment
Hide comment
@donatj

donatj Jan 28, 2015

Collaborator

Also if you could create a small sample script that causes the issue, that'd be very helpful.

Collaborator

donatj commented Jan 28, 2015

Also if you could create a small sample script that causes the issue, that'd be very helpful.

@ArturGrigio

This comment has been minimized.

Show comment
Hide comment
@ArturGrigio

ArturGrigio Jan 31, 2015

  1. I've downloaded the latest version from git
  2. I installed it on PHP Version 5.3.29
  3. I tested it on OSX Mavericks and Yosemite (virtual machine)
  4. I am not using any third party software (i.e. winrar)

I wrote my own version of something similar (https://github.com/ArturGrigio/php-Zip-Download-of-Large-Files-using-Buffer), and I was having the same loop issue. The fix for mine was static casing the stream command to string before sending to the buffer. I believe something about the escape characters was messing with it.

ArturGrigio commented Jan 31, 2015

  1. I've downloaded the latest version from git
  2. I installed it on PHP Version 5.3.29
  3. I tested it on OSX Mavericks and Yosemite (virtual machine)
  4. I am not using any third party software (i.e. winrar)

I wrote my own version of something similar (https://github.com/ArturGrigio/php-Zip-Download-of-Large-Files-using-Buffer), and I was having the same loop issue. The fix for mine was static casing the stream command to string before sending to the buffer. I believe something about the escape characters was messing with it.

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Jan 31, 2015

Owner

Is it possible to send us the file and the exact code you're running?

Owner

maennchen commented Jan 31, 2015

Is it possible to send us the file and the exact code you're running?

@donatj

This comment has been minimized.

Show comment
Hide comment
@donatj

donatj Feb 1, 2015

Collaborator

Yes, if you could send us the code and/or an example zip that would be very helpful resolving this.

Collaborator

donatj commented Feb 1, 2015

Yes, if you could send us the code and/or an example zip that would be very helpful resolving this.

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Feb 18, 2015

Owner

We can't reproduce the error if we don't have this data. I'm therefore closing the issue.
Feel free to reopen it, if we have the required data.

Owner

maennchen commented Feb 18, 2015

We can't reproduce the error if we don't have this data. I'm therefore closing the issue.
Feel free to reopen it, if we have the required data.

@maennchen maennchen closed this Feb 18, 2015

@maennchen maennchen added the bug label Feb 18, 2015

@pooshok

This comment has been minimized.

Show comment
Hide comment
@pooshok

pooshok commented Jan 26, 2016

Here is the solution splitbrain/crocofile#2

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Jan 26, 2016

Owner

@pooshok The change referenced in you link was implemented years ago...
https://github.com/maennchen/ZipStream-PHP/blob/master/src/ZipStream.php#L413

Owner

maennchen commented Jan 26, 2016

@pooshok The change referenced in you link was implemented years ago...
https://github.com/maennchen/ZipStream-PHP/blob/master/src/ZipStream.php#L413

@pooshok

This comment has been minimized.

Show comment
Hide comment
@pooshok

pooshok Jan 26, 2016

Oh! sorry. I downloaded and used version 0.2.2 from here http://pablotron.org/software/zipstream-php/ and thought it latest.

pooshok commented Jan 26, 2016

Oh! sorry. I downloaded and used version 0.2.2 from here http://pablotron.org/software/zipstream-php/ and thought it latest.

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Jan 26, 2016

Owner

@pooshok:
There aren't any changes on the original since the year 2004. That's why I forked it.

Owner

maennchen commented Jan 26, 2016

@pooshok:
There aren't any changes on the original since the year 2004. That's why I forked it.

@code8082

This comment has been minimized.

Show comment
Hide comment
@code8082

code8082 Oct 4, 2017

I'm having the same problem when I try to zip files dynamically. It just keeps making these zips that open into cpgz in an infinite loop.

`<?php
ob_start();
// load zipstream class
require 'zipstream/ZipStream.php';

$zip = new ZipStream\ZipStream('download.zip');

// connect to the database
include('connect-db.php');

$project_id_temp = '75';

$query = "SELECT * FROM project_images WHERE project_id = ".$project_id_temp;
$result = $conn->query($query);

if ($result == false) {
$error_message = $conn->error;
echo "

An error occurred: $error_message

";
exit () ;
}

$row_count = $result->num_rows;

if(mysqli_num_rows($result) > 0){
for ($i = 0; $i < $row_count; $i++) :
$image = $result->fetch_assoc();
$zip->addFileFromPath($image['img_name'], "uploads/".$project_id_temp."/".$image['img_name']);
endfor;
$zip->finish();
}
?>`

code8082 commented Oct 4, 2017

I'm having the same problem when I try to zip files dynamically. It just keeps making these zips that open into cpgz in an infinite loop.

`<?php
ob_start();
// load zipstream class
require 'zipstream/ZipStream.php';

$zip = new ZipStream\ZipStream('download.zip');

// connect to the database
include('connect-db.php');

$project_id_temp = '75';

$query = "SELECT * FROM project_images WHERE project_id = ".$project_id_temp;
$result = $conn->query($query);

if ($result == false) {
$error_message = $conn->error;
echo "

An error occurred: $error_message

";
exit () ;
}

$row_count = $result->num_rows;

if(mysqli_num_rows($result) > 0){
for ($i = 0; $i < $row_count; $i++) :
$image = $result->fetch_assoc();
$zip->addFileFromPath($image['img_name'], "uploads/".$project_id_temp."/".$image['img_name']);
endfor;
$zip->finish();
}
?>`

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Oct 4, 2017

Owner

@code8082 Can you look at the zip file with a text editor and make sure that there are no PHP warnings?

Owner

maennchen commented Oct 4, 2017

@code8082 Can you look at the zip file with a text editor and make sure that there are no PHP warnings?

@code8082

This comment has been minimized.

Show comment
Hide comment
@code8082

code8082 Oct 4, 2017

No warnings I can see. If i hard code the files it works fine. If i dynamically add them like above, it doesn't work and makes this zip that creates a cpgz file and then a zip and then a cpgz file.

Hard-coded version:
`<?php
require 'zipstream/ZipStream.php';

$zip = new ZipStream\ZipStream('download.zip');

$zip->addFileFromPath("7736c57f9fdc596cc8f919f362e92878_3cd0ba0d24d7b.jpg", "uploads/75/7736c57f9fdc596cc8f919f362e92878_3cd0ba0d24d7b.jpg");

$zip->addFileFromPath("b460e068faf57f6ed84f84114ea2368f_862f49e57c899.jpg", "uploads/75/b460e068faf57f6ed84f84114ea2368f_862f49e57c899.jpg");

$zip->finish();

?>`

code8082 commented Oct 4, 2017

No warnings I can see. If i hard code the files it works fine. If i dynamically add them like above, it doesn't work and makes this zip that creates a cpgz file and then a zip and then a cpgz file.

Hard-coded version:
`<?php
require 'zipstream/ZipStream.php';

$zip = new ZipStream\ZipStream('download.zip');

$zip->addFileFromPath("7736c57f9fdc596cc8f919f362e92878_3cd0ba0d24d7b.jpg", "uploads/75/7736c57f9fdc596cc8f919f362e92878_3cd0ba0d24d7b.jpg");

$zip->addFileFromPath("b460e068faf57f6ed84f84114ea2368f_862f49e57c899.jpg", "uploads/75/b460e068faf57f6ed84f84114ea2368f_862f49e57c899.jpg");

$zip->finish();

?>`

@maennchen

This comment has been minimized.

Show comment
Hide comment
@maennchen

maennchen Oct 4, 2017

Owner

@code8082 If it works hard-coded it‘s likely not an error of the library. Could you try to dump the files instead of adding them to a zip to see if you code other than the zip works?

Owner

maennchen commented Oct 4, 2017

@code8082 If it works hard-coded it‘s likely not an error of the library. Could you try to dump the files instead of adding them to a zip to see if you code other than the zip works?

@donatj

This comment has been minimized.

Show comment
Hide comment
@donatj

donatj Oct 4, 2017

Collaborator

@code8082 Could you try removing the closing php tag ?> sometimes accidental trailing whitespace can cause nightmares.

Collaborator

donatj commented Oct 4, 2017

@code8082 Could you try removing the closing php tag ?> sometimes accidental trailing whitespace can cause nightmares.

@code8082

This comment has been minimized.

Show comment
Hide comment
@code8082

code8082 Oct 4, 2017

Hey donatj... I tried removing the ?> tag.. same issue.

how do i dump the files maennchen?

code8082 commented Oct 4, 2017

Hey donatj... I tried removing the ?> tag.. same issue.

how do i dump the files maennchen?

@SOSTheBlack

This comment has been minimized.

Show comment
Hide comment
@SOSTheBlack

SOSTheBlack Mar 7, 2018

This worked for me and fixed my bug.

ob_end_clean();
readfile('name.zip');

SOSTheBlack commented Mar 7, 2018

This worked for me and fixed my bug.

ob_end_clean();
readfile('name.zip');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment