Fixes bug involving long file names in tarballs
authorMatthias Schmidt <gravatronics@live.com>
Mon, 27 Feb 2012 17:35:26 +0000 (18:35 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 27 Feb 2012 17:38:11 +0000 (18:38 +0100)
wcfsetup/install/files/lib/system/io/Tar.class.php

index 7ac9596179a37090f27d029424ffbe3aa14ccd4a..0ef0b1006db9e57661e899000c8c9bb0199896f3 100644 (file)
@@ -269,15 +269,31 @@ class Tar {
                $i = 0;
                
                // Read the 512 bytes header
+               $longFilename = null;
                while (strlen($binaryData = $this->file->read(512)) != 0) {
                        // read header
                        $header = $this->readHeader($binaryData);
                        if ($header === false) {
                                continue;       
                        }
-                       $this->contentList[$i] = $header;
-                       $this->contentList[$i]['index'] = $i;
-                       $i++;
+                       
+                       // fixes a bug that files with long names aren't correctly
+                       // extracted
+                       if ($longFilename !== null) {
+                               $header['filename'] = $longFilename;
+                               $longFilename = null;
+                       }
+                       if ($header['typeflag'] == 'L') {
+                               $fileData = unpack("a".$header['size']."filename", $this->file->read(512));
+                               $longFilename = $fileData['filename'];
+                               $header['size'] = 0;
+                       }
+                       // don't include the @LongLink file in the content list
+                       else {
+                               $this->contentList[$i] = $header;
+                               $this->contentList[$i]['index'] = $i;
+                               $i++;
+                       }
                        
                        $this->file->seek($this->file->tell() + (512 * ceil(($header['size'] / 512))));
                }