aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_compress.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/functions_compress.php')
-rw-r--r--phpBB/includes/functions_compress.php68
1 files changed, 56 insertions, 12 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php
index 36b7d575d9..021079deef 100644
--- a/phpBB/includes/functions_compress.php
+++ b/phpBB/includes/functions_compress.php
@@ -179,7 +179,7 @@ class compress_zip extends compress
* Extract archive
*/
function extract($dst)
- {
+ {
// Loop the file, looking for files and folders
$dd_try = false;
rewind($this->fp);
@@ -215,6 +215,12 @@ class compress_zip extends compress
// Create and folders and subfolders if they do not exist
foreach ($folders as $folder)
{
+ $folder = trim($folder);
+ if (!$folder)
+ {
+ continue;
+ }
+
$str = (!empty($str)) ? $str . '/' . $folder : $folder;
if (!is_dir($str))
{
@@ -231,13 +237,19 @@ class compress_zip extends compress
}
else
{
- // Some archivers are punks, they don't don't include folders in their archives!
+ // Some archivers are punks, they don't include folders in their archives!
$str = '';
$folders = explode('/', pathinfo($target_filename, PATHINFO_DIRNAME));
// Create and folders and subfolders if they do not exist
foreach ($folders as $folder)
{
+ $folder = trim($folder);
+ if (!$folder)
+ {
+ continue;
+ }
+
$str = (!empty($str)) ? $str . '/' . $folder : $folder;
if (!is_dir($str))
{
@@ -267,7 +279,7 @@ class compress_zip extends compress
// Not compressed
fwrite($fp, $content);
break;
-
+
case 8:
// Deflate
fwrite($fp, gzinflate($content, $data['uc_size']));
@@ -278,7 +290,7 @@ class compress_zip extends compress
fwrite($fp, bzdecompress($content));
break;
}
-
+
fclose($fp);
break;
@@ -288,11 +300,11 @@ class compress_zip extends compress
// This case should simply never happen.. but it does exist..
case "\x50\x4b\x05\x06":
break 2;
-
+
// 'Packed to Removable Disk', ignore it and look for the next signature...
case 'PK00':
continue 2;
-
+
// We have encountered a header that is weird. Lets look for better data...
default:
if (!$dd_try)
@@ -507,16 +519,24 @@ class compress_tar extends compress
$tmp = unpack('A12size', substr($buffer, 124, 12));
$filesize = octdec((int) trim($tmp['size']));
+ $target_filename = "$dst$filename";
+
if ($filetype == 5)
{
- if (!is_dir("$dst$filename"))
+ if (!is_dir($target_filename))
{
$str = '';
- $folders = explode('/', "$dst$filename");
+ $folders = explode('/', $target_filename);
// Create and folders and subfolders if they do not exist
foreach ($folders as $folder)
{
+ $folder = trim($folder);
+ if (!$folder)
+ {
+ continue;
+ }
+
$str = (!empty($str)) ? $str . '/' . $folder : $folder;
if (!is_dir($str))
{
@@ -529,17 +549,41 @@ class compress_tar extends compress
}
}
}
- else if ($filesize != 0 && ($filetype == 0 || $filetype == "\0"))
+ else if ($filesize >= 0 && ($filetype == 0 || $filetype == "\0"))
{
+ // Some archivers are punks, they don't properly order the folders in their archives!
+ $str = '';
+ $folders = explode('/', pathinfo($target_filename, PATHINFO_DIRNAME));
+
+ // Create and folders and subfolders if they do not exist
+ foreach ($folders as $folder)
+ {
+ $folder = trim($folder);
+ if (!$folder)
+ {
+ continue;
+ }
+
+ $str = (!empty($str)) ? $str . '/' . $folder : $folder;
+ if (!is_dir($str))
+ {
+ if (!@mkdir($str, 0777))
+ {
+ trigger_error("Could not create directory $folder");
+ }
+ @chmod($str, 0777);
+ }
+ }
+
// Write out the files
- if (!($fp = fopen("$dst$filename", 'wb')))
+ if (!($fp = fopen($target_filename, 'wb')))
{
trigger_error("Couldn't create file $filename");
}
- @chmod("$dst$filename", 0777);
+ @chmod($target_filename, 0777);
// Grab the file contents
- fwrite($fp, $fzread($this->fp, ($filesize + 511) &~ 511), $filesize);
+ fwrite($fp, ($filesize) ? $fzread($this->fp, ($filesize + 511) &~ 511) : '', $filesize);
fclose($fp);
}
}