From 530d672995040c320a9506a0b93258a49c4d0b29 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <gohr@cosmocode.de>
Date: Thu, 13 Aug 2015 10:40:35 +0200
Subject: [PATCH] updated php-archive to 1.0.7 fixes #1296

---
 .gitignore                                    |  2 +
 composer.lock                                 | 10 ++--
 vendor/composer/ClassLoader.php               |  8 +--
 vendor/composer/installed.json                | 12 ++---
 vendor/splitbrain/php-archive/.gitignore      |  3 +-
 vendor/splitbrain/php-archive/README.md       | 14 ++++--
 vendor/splitbrain/php-archive/src/Archive.php |  4 ++
 .../splitbrain/php-archive/src/FileInfo.php   |  1 +
 vendor/splitbrain/php-archive/src/Tar.php     | 50 ++++++++++++++-----
 9 files changed, 70 insertions(+), 34 deletions(-)

diff --git a/.gitignore b/.gitignore
index dd5c9cf18..7410ee1c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,3 +69,5 @@ vendor/*/*/test/*
 vendor/*/*/doc/*
 vendor/*/*/docs/*
 vendor/*/*/contrib/*
+vendor/splitbrain/php-archive/apigen.neon
+vendor/splitbrain/php-archive/generate-api.sh
diff --git a/composer.lock b/composer.lock
index 9aa165902..f504ba638 100644
--- a/composer.lock
+++ b/composer.lock
@@ -54,16 +54,16 @@
         },
         {
             "name": "splitbrain/php-archive",
-            "version": "1.0.4",
+            "version": "1.0.7",
             "source": {
                 "type": "git",
                 "url": "https://github.com/splitbrain/php-archive.git",
-                "reference": "6572e78ef9d064eeb5c74d4ffe61b473a4996b68"
+                "reference": "c075304b44c4aadff0718af445e86bf730f331ff"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/splitbrain/php-archive/zipball/6572e78ef9d064eeb5c74d4ffe61b473a4996b68",
-                "reference": "6572e78ef9d064eeb5c74d4ffe61b473a4996b68",
+                "url": "https://api.github.com/repos/splitbrain/php-archive/zipball/c075304b44c4aadff0718af445e86bf730f331ff",
+                "reference": "c075304b44c4aadff0718af445e86bf730f331ff",
                 "shasum": ""
             },
             "require": {
@@ -97,7 +97,7 @@
                 "unzip",
                 "zip"
             ],
-            "time": "2015-07-24 11:36:49"
+            "time": "2015-08-12 13:24:34"
         }
     ],
     "packages-dev": [],
diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php
index 4e05d3b15..5e1469e83 100644
--- a/vendor/composer/ClassLoader.php
+++ b/vendor/composer/ClassLoader.php
@@ -351,7 +351,7 @@ class ClassLoader
             foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
                 if (0 === strpos($class, $prefix)) {
                     foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
-                        if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
+                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
                             return $file;
                         }
                     }
@@ -361,7 +361,7 @@ class ClassLoader
 
         // PSR-4 fallback dirs
         foreach ($this->fallbackDirsPsr4 as $dir) {
-            if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
+            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
                 return $file;
             }
         }
@@ -380,7 +380,7 @@ class ClassLoader
             foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
                 if (0 === strpos($class, $prefix)) {
                     foreach ($dirs as $dir) {
-                        if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                             return $file;
                         }
                     }
@@ -390,7 +390,7 @@ class ClassLoader
 
         // PSR-0 fallback dirs
         foreach ($this->fallbackDirsPsr0 as $dir) {
-            if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                 return $file;
             }
         }
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 9b20b8a09..0510ac994 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -49,17 +49,17 @@
     },
     {
         "name": "splitbrain/php-archive",
-        "version": "1.0.4",
-        "version_normalized": "1.0.4.0",
+        "version": "1.0.7",
+        "version_normalized": "1.0.7.0",
         "source": {
             "type": "git",
             "url": "https://github.com/splitbrain/php-archive.git",
-            "reference": "6572e78ef9d064eeb5c74d4ffe61b473a4996b68"
+            "reference": "c075304b44c4aadff0718af445e86bf730f331ff"
         },
         "dist": {
             "type": "zip",
-            "url": "https://api.github.com/repos/splitbrain/php-archive/zipball/6572e78ef9d064eeb5c74d4ffe61b473a4996b68",
-            "reference": "6572e78ef9d064eeb5c74d4ffe61b473a4996b68",
+            "url": "https://api.github.com/repos/splitbrain/php-archive/zipball/c075304b44c4aadff0718af445e86bf730f331ff",
+            "reference": "c075304b44c4aadff0718af445e86bf730f331ff",
             "shasum": ""
         },
         "require": {
@@ -68,7 +68,7 @@
         "require-dev": {
             "phpunit/phpunit": "4.5.*"
         },
-        "time": "2015-07-24 11:36:49",
+        "time": "2015-08-12 13:24:34",
         "type": "library",
         "installation-source": "dist",
         "autoload": {
diff --git a/vendor/splitbrain/php-archive/.gitignore b/vendor/splitbrain/php-archive/.gitignore
index 39b851b56..c6277c187 100644
--- a/vendor/splitbrain/php-archive/.gitignore
+++ b/vendor/splitbrain/php-archive/.gitignore
@@ -3,5 +3,6 @@
 composer.phar
 vendor/
 composer.lock
-
+apigen.phar
+docs/
 
diff --git a/vendor/splitbrain/php-archive/README.md b/vendor/splitbrain/php-archive/README.md
index 6c5780a7a..f18764b61 100644
--- a/vendor/splitbrain/php-archive/README.md
+++ b/vendor/splitbrain/php-archive/README.md
@@ -19,8 +19,11 @@ Usage
 -----
 
 The usage for the Zip and Tar classes are basically the same. Here are some
-examples for working with TARs to get you started. Check the source code
-comments for more info
+examples for working with TARs to get you started.
+
+Check the [API docs](https://splitbrain.github.io/php-archive/) for more
+info.
+
 
 ```php
 require_once 'vendor/autoload.php';
@@ -51,16 +54,17 @@ $tar->close();
 // To create a TAR archive directly in memory, create() it, add*()
 // files and then either save() or getArchive() it:
 $tar = new Tar();
+$tar->setCompression(9, Archive::COMPRESS_BZIP);
 $tar->create();
 $tar->addFile(...);
 $tar->addData(...);
 ...
-$tar->save('myfile.tgz'); // compresses and saves it
-echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it
+$tar->save('myfile.tbz'); // compresses and saves it
+echo $tar->getArchive(); // compresses and returns it
 ```
 
 Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore
 you can call ```setCompression``` before each ```addFile()``` and ```addData()``` function call.
 
 The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to
-an archive. 
\ No newline at end of file
+an archive. 
diff --git a/vendor/splitbrain/php-archive/src/Archive.php b/vendor/splitbrain/php-archive/src/Archive.php
index c60fea777..d672cc6ec 100644
--- a/vendor/splitbrain/php-archive/src/Archive.php
+++ b/vendor/splitbrain/php-archive/src/Archive.php
@@ -126,3 +126,7 @@ class ArchiveIOException extends \Exception
 class ArchiveIllegalCompressionException extends \Exception
 {
 }
+
+class ArchiveCorruptedException extends \Exception
+{
+}
diff --git a/vendor/splitbrain/php-archive/src/FileInfo.php b/vendor/splitbrain/php-archive/src/FileInfo.php
index c443aa977..612f924c3 100644
--- a/vendor/splitbrain/php-archive/src/FileInfo.php
+++ b/vendor/splitbrain/php-archive/src/FileInfo.php
@@ -61,6 +61,7 @@ class FileInfo
         $file->setMode(fileperms($path));
         $file->setOwner(fileowner($path));
         $file->setGroup(filegroup($path));
+        $file->setSize(filesize($path));
         $file->setUid($stat['uid']);
         $file->setGid($stat['gid']);
         $file->setMtime($stat['mtime']);
diff --git a/vendor/splitbrain/php-archive/src/Tar.php b/vendor/splitbrain/php-archive/src/Tar.php
index bd78136da..e29c7d5a6 100644
--- a/vendor/splitbrain/php-archive/src/Tar.php
+++ b/vendor/splitbrain/php-archive/src/Tar.php
@@ -36,6 +36,8 @@ class Tar extends Archive
         $this->compressioncheck($type);
         $this->comptype  = $type;
         $this->complevel = $level;
+        if($level == 0) $this->comptype = Archive::COMPRESS_NONE;
+        if($type == Archive::COMPRESS_NONE) $this->complevel = 0;
     }
 
     /**
@@ -366,7 +368,7 @@ class Tar extends Archive
     public function save($file)
     {
         if ($this->comptype === Archive::COMPRESS_AUTO) {
-            $this->setCompression($this->filetype($this->complevel, $file));
+            $this->setCompression($this->complevel, $this->filetype($file));
         }
 
         if (!file_put_contents($file, $this->getArchive())) {
@@ -429,7 +431,12 @@ class Tar extends Archive
             @gzseek($this->fh, $bytes, SEEK_CUR);
         } elseif ($this->comptype === Archive::COMPRESS_BZIP) {
             // there is no seek in bzip2, we simply read on
-            @bzread($this->fh, $bytes);
+            // bzread allows to read a max of 8kb at once
+            while($bytes) {
+                $toread = min(8192, $bytes);
+                @bzread($this->fh, $toread);
+                $bytes -= $toread;
+            }
         } else {
             @fseek($this->fh, $bytes, SEEK_CUR);
         }
@@ -513,15 +520,19 @@ class Tar extends Archive
     /**
      * Decode the given tar file header
      *
-     * @param string $block a 512 byte block containign the header data
-     * @return array|bool
+     * @param string $block a 512 byte block containing the header data
+     * @return array|false returns false when this was a null block
+     * @throws ArchiveCorruptedException
      */
     protected function parseHeader($block)
     {
         if (!$block || strlen($block) != 512) {
-            return false;
+            throw new ArchiveCorruptedException('Unexpected length of header');
         }
 
+        // null byte blocks are ignored
+        if(trim($block) === '') return false;
+
         for ($i = 0, $chks = 0; $i < 148; $i++) {
             $chks += ord($block[$i]);
         }
@@ -535,12 +546,12 @@ class Tar extends Archive
             $block
         );
         if (!$header) {
-            return false;
+            throw new ArchiveCorruptedException('Failed to parse header');
         }
 
         $return['checksum'] = OctDec(trim($header['checksum']));
         if ($return['checksum'] != $chks) {
-            return false;
+            throw new ArchiveCorruptedException('Header does not match it\'s checksum');
         }
 
         $return['filename'] = trim($header['filename']);
@@ -613,7 +624,9 @@ class Tar extends Archive
     }
 
     /**
-     * Guesses the wanted compression from the given filename extension
+     * Guesses the wanted compression from the given file
+     *
+     * Uses magic bytes for existing files, the file extension otherwise
      *
      * You don't need to call this yourself. It's used when you pass Archive::COMPRESS_AUTO somewhere
      *
@@ -622,14 +635,25 @@ class Tar extends Archive
      */
     public function filetype($file)
     {
+        // for existing files, try to read the magic bytes
+        if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
+            $fh = fopen($file, 'rb');
+            if(!$fh) return false;
+            $magic = fread($fh, 5);
+            fclose($fh);
+
+            if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP;
+            if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP;
+        }
+
+        // otherwise rely on file name
         $file = strtolower($file);
         if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
-            $comptype = Archive::COMPRESS_GZIP;
+            return Archive::COMPRESS_GZIP;
         } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {
-            $comptype = Archive::COMPRESS_BZIP;
-        } else {
-            $comptype = Archive::COMPRESS_NONE;
+            return Archive::COMPRESS_BZIP;
         }
-        return $comptype;
+
+        return Archive::COMPRESS_NONE;
     }
 }
-- 
GitLab