Improve Zip and ZipWriter
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 29 May 2013 13:04:51 +0000 (15:04 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 29 May 2013 13:08:55 +0000 (15:08 +0200)
see http://beta.woltlab.com/index.php/Thread/1372-ZipWriter-erzeugt-fehlerhafte-Datei/

wcfsetup/install/files/lib/system/io/Zip.class.php
wcfsetup/install/files/lib/system/io/ZipWriter.class.php

index 2950ed4637de170f7a6e10a424384f5f9feeb301..18be9bfbcfd59b475770d0cc48da4d183e969b3c 100644 (file)
@@ -177,10 +177,10 @@ class Zip extends File implements IArchive {
                        $data['mtime'] = mktime($hour, $minute, $second, $month, $day, $year);
                        
                        $data += unpack('Vcrc32/VcompressedSize/Vsize/vfilenameLength/vextraFieldLength/vfileCommentLength/vdiskNo/vinternalAttr/vexternalAttr', $this->read(26));
-                       if ($data['compressedSize'] > 0) $data['type'] = 'file';
-                       else $data['type'] = 'folder';
                        $data['offset'] = $this->readAndUnpack(4, 'v');
                        $data['filename'] = $this->read($data['filenameLength']);
+                       if (substr($data['filename'], -1) == '/') $data['type'] = 'folder';
+                       else $data['type'] = 'file';
                        
                        // read extraField
                        if ($data['extraFieldLength'] > 0) $data['extraField'] = $this->read($data['extraFieldLength']);
@@ -295,7 +295,7 @@ class Zip extends File implements IArchive {
                
                // read contents
                $header['type'] = 'file';
-               if ($header['compressedSize'] > 0) $content = $this->read($header['compressedSize']);
+               if (substr($header['filename'], -1) != '/') $content = $this->read($header['compressedSize']);
                else {
                        $header['type'] = 'folder';
                        $content = false;
index d56ac10a1e613aad7023d270059b51b1e5b446e3..18a520a807039b390cf1837e5948b296c0ab4f79 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\io;
+use wcf\util\FileUtil;
 use wcf\util\StringUtil;
 
 /**
@@ -26,6 +27,7 @@ class ZipWriter {
        public function addDir($name) {
                // replace backward slashes with forward slashes in the dirname
                $name = StringUtil::replace("\\", "/", $name);
+               $name = FileUtil::addTrailingSlash($name);
                
                // construct the general header information for the directory
                $header = "\x50\x4b\x03\x04";