From 79c72890e67dbd0a67bb85466886e4dd7e86a6f5 Mon Sep 17 00:00:00 2001 From: David M Date: Sun, 20 Apr 2008 04:39:04 +0000 Subject: #14429 git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8505 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 36b7d575d9..852f1c967a 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -231,7 +231,7 @@ 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)); @@ -507,12 +507,14 @@ 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) @@ -529,17 +531,35 @@ 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) + { + $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); } } -- cgit v1.2.1 From cc6d084368a260be9e0c44d3d09da46c250ea776 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 9 Jun 2008 17:44:32 +0000 Subject: check if folder is not empty (may happen for absolute paths). Thanks paul git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8639 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 852f1c967a..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)) { @@ -238,6 +244,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)) { @@ -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) @@ -519,6 +531,12 @@ class compress_tar 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)) { @@ -540,6 +558,12 @@ class compress_tar 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)) { -- cgit v1.2.1 From 068096531f297d188afea88190cd838ccae662cb Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sat, 16 Aug 2008 19:06:18 +0000 Subject: the chmod change i already had within the changelog (by mistake). This should further secure writable directories and created files. Installation need to be tested on different hosts. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8763 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 021079deef..18106a155b 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -228,7 +228,7 @@ class compress_zip extends compress { trigger_error("Could not create directory $folder"); } - @chmod($str, 0777); + phpbb_chmod($str, 'rwrite'); } } } @@ -257,7 +257,7 @@ class compress_zip extends compress { trigger_error("Could not create directory $folder"); } - @chmod($str, 0777); + phpbb_chmod($str, 'rwrite'); } } } @@ -544,7 +544,7 @@ class compress_tar extends compress { trigger_error("Could not create directory $folder"); } - @chmod($str, 0777); + phpbb_chmod($str, 'rwrite'); } } } @@ -571,7 +571,7 @@ class compress_tar extends compress { trigger_error("Could not create directory $folder"); } - @chmod($str, 0777); + phpbb_chmod($str, 'rwrite'); } } @@ -580,7 +580,7 @@ class compress_tar extends compress { trigger_error("Couldn't create file $filename"); } - @chmod($target_filename, 0777); + phpbb_chmod($target_filename, 'rwrite'); // Grab the file contents fwrite($fp, ($filesize) ? $fzread($this->fp, ($filesize + 511) &~ 511) : '', $filesize); -- cgit v1.2.1 From 6c763cd8b65c1b63d57fb0f176d2c98a44076df1 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 22 Aug 2008 12:52:48 +0000 Subject: change the way we do chmodd'ing. I know, my implementation really sucked... good we have motivated community members who point this out. ;) Thanks to faw for providing a way better function and for discussing and also abiding to our needs. :) LEW21 should maybe credited too... he gave the inspiration without knowing it. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8780 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 18106a155b..881e1ba5cc 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -228,7 +228,7 @@ class compress_zip extends compress { trigger_error("Could not create directory $folder"); } - phpbb_chmod($str, 'rwrite'); + phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE); } } } @@ -257,7 +257,7 @@ class compress_zip extends compress { trigger_error("Could not create directory $folder"); } - phpbb_chmod($str, 'rwrite'); + phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE); } } } @@ -544,7 +544,7 @@ class compress_tar extends compress { trigger_error("Could not create directory $folder"); } - phpbb_chmod($str, 'rwrite'); + phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE); } } } @@ -571,7 +571,7 @@ class compress_tar extends compress { trigger_error("Could not create directory $folder"); } - phpbb_chmod($str, 'rwrite'); + phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE); } } @@ -580,7 +580,7 @@ class compress_tar extends compress { trigger_error("Couldn't create file $filename"); } - phpbb_chmod($target_filename, 'rwrite'); + phpbb_chmod($target_filename, CHMOD_READ); // Grab the file contents fwrite($fp, ($filesize) ? $fzread($this->fp, ($filesize + 511) &~ 511) : '', $filesize); -- cgit v1.2.1 From ab9715a9fe5577921180a6f77b5a89b990665b6e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 Jul 2009 11:32:27 +0000 Subject: Fix bugs #46615 & #46945 - Fail gracefully if store folder is not writable during update. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9768 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 881e1ba5cc..590daabf1d 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -155,7 +155,12 @@ class compress_zip extends compress */ function compress_zip($mode, $file) { - return $this->fp = @fopen($file, $mode . 'b'); + $this->fp = @fopen($file, $mode . 'b'); + + if (!$this->fp) + { + trigger_error('Unable to open file ' . $file . ' [' . $mode . 'b]'); + } } /** -- cgit v1.2.1 From ad14664a3a53c270511bc19392c38b60a2c3e3ff Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Mon, 18 Jan 2010 16:41:21 +0000 Subject: - Bug #56255 - Moving topics to a forum where you are on queue - Allow some error handling in compress class by returning false if file does not exist. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10427 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_compress.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes/functions_compress.php') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 590daabf1d..f17c780a65 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -80,6 +80,11 @@ class compress } } } + else + { + // $src does not exist + return false; + } return true; } @@ -89,6 +94,11 @@ class compress */ function add_custom_file($src, $filename) { + if (!file_exists($src)) + { + return false; + } + $this->data($filename, file_get_contents($src), false, stat($src)); return true; } -- cgit v1.2.1