Corrupt extraction with ZipArchive in PHP

msoutopico :

I have a PHP script that must unzip some uploads. The uploads are packed folders, basically zip files with a custom extension.

I am having problems with some zip files packed in one machine, but not with the same folder packed in another machine. In both cases, the compression is done with the same Java library.

This is the expected result, which then PHP further proceses: correct extraction

This is the corrupted result, which makes PHP choke: corrupted extraction

If I look at their permissions, this is what I see (01_Orig is okay, 02_Modif is corrupted): permissions

If I look at the two packages with unzip -l (the first one is okay, the second one is corrupt): unzip -l

And this is my PHP function (which is the same in both cases):

$uploads = "uploads_dir/";
$dir = new DirectoryIterator("uploads_dir/");

foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot()) {
        $filename = $fileinfo->getFilename();
        $zip = new ZipArchive;
        $res = $zip->open($uploads . $fileinfo);
        if ($res === TRUE) {
            $zip->extractTo($uploads . $filename . "_extracted");
            $zip->close();
        } else {
            echo "Unable to unzip";
        }
    }
}

Both uploads look fine when I manually unzip or open them with 7zip in my Windows machine.

If I create two hex dumps of both zip files and compare them, this is what I get: https://gist.github.com/msoutopico/22a9ef647381c2e4d26313f135c526e2

Thanks a lot in advance for any tips.

UPDATE:

In case it's relevant, the zip files are created (saved) in a linux server, and both machines where this is done (the one that works, and the one that corrupt the package) run Windows 10.

msoutopico :

Sorted. Version 2 of the plugin was tweaked to transform path separators from \ to / in filenames. Now, even though the version 3 of the plugin was installed in both machines, in the faulty machine there was also an older one (version 1, previous to that tweak), which is the one that was being used instead of version 3. Just removing the version 1 duplicate has fixed the problem. @pmqs was right. Thank you everyone for helping me quickly solve this!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=217548&siteId=1