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

zip open throws exception when reading a zip file in a loop. #96

Open
saisubodhMSFT opened this issue Aug 29, 2023 · 1 comment
Open

Comments

@saisubodhMSFT
Copy link

saisubodhMSFT commented Aug 29, 2023

Q A
Library version(s): 4.0.1
PHP version(s): 8.2
OS (with bit depth): Alpine Linux 3.16

Description
In the following example code, the program throws an exception at $zip->openFiile() after 2nd iteration of the for loop.

How to reproduce

function testZip() {
// path to empty zip file
$zipFilePath = 'path/to/zipfile';

    for ($i=0; $i<20; $i++) {
            $zip = new \PhpZip\ZipFile();
            if ($zip->openFile($zipFilePath)) {
                    $fileContents = file_get_contents('example.txt');
                    $zip->addFromString('example' . strval($i) . '.txt', $fileContents);
                    $zip->saveAsFile($zipFilePath);
                    $zip->close();
            }
    }        

}

Additional context
Error Message: Exception: example0.txt (expected Local File Header)

Stack Trace:

File: ../vendor/nelexa/zip/src/IO/ZipReader.php
Line: 615
Trace:
#0 /home/site/wwwroot/wp-content/plugins/azure_app_service_migration/vendor/nelexa/zip/src/IO/ZipReader.php(515): PhpZip\IO\ZipReader->loadLocalExtraFields(Object(PhpZip\Model\ZipEntry))
#1 /home/site/wwwroot/wp-content/plugins/azure_app_service_migration/vendor/nelexa/zip/src/IO/ZipReader.php(363): PhpZip\IO\ZipReader->readZipEntry(Resource id #69)
#2 /home/site/wwwroot/wp-content/plugins/azure_app_service_migration/vendor/nelexa/zip/src/IO/ZipReader.php(117): PhpZip\IO\ZipReader->readCentralDirectory(Object(PhpZip\Model\EndOfCentralDirectory))
#3 /home/site/wwwroot/wp-content/plugins/azure_app_service_migration/vendor/nelexa/zip/src/ZipFile.php(152): PhpZip\IO\ZipReader->read()
#4 /home/site/wwwroot/wp-content/plugins/azure_app_service_migration/vendor/nelexa/zip/src/ZipFile.php(113): PhpZip\ZipFile->openFromStream(Resource id #68, Array)

@odan
Copy link
Contributor

odan commented Aug 30, 2023

I have tried to reproduce this problem on my computer and can say that this is not the case.

The error message indicates that your "original" ZIP file may be "corrupted".

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

2 participants