From 32d360ece7ed38ab8c30c08fed593a4dfb7a97ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Apr 2016 18:20:41 +0200 Subject: [PATCH 1/5] Check for fopen return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/File.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/File.php b/libraries/File.php index 4948083a21..b350a2229c 100644 --- a/libraries/File.php +++ b/libraries/File.php @@ -636,7 +636,6 @@ class File $this->errorUnsupported(); return false; } - break; case 'none': $this->_handle = @fopen($this->getName(), 'r'); break; @@ -645,7 +644,7 @@ class File return false; } - return true; + return ($this->_handle !== false); } public function openZip($specific_entry = null) From 33cd6f3270348ebb2dd1f1b08f3a6ee2b7a1bf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Apr 2016 18:24:14 +0200 Subject: [PATCH 2/5] Add missing docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/File.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/File.php b/libraries/File.php index b350a2229c..1166e4333a 100644 --- a/libraries/File.php +++ b/libraries/File.php @@ -647,6 +647,13 @@ class File return ($this->_handle !== false); } + /** + * Opens file from zip + * + * @param string|null $specific_entry Entry to open + * + * @return bool + */ public function openZip($specific_entry = null) { include_once './libraries/zip_extension.lib.php'; @@ -675,6 +682,8 @@ class File /** * Closes the file + * + * @return void */ public function close() { @@ -691,6 +700,8 @@ class File /** * Reads data from file * + * @param int $size Number of bytes to read + * * @return string */ public function read($size) From 267bf1e681e0398e19162d132840f4fe9e508395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Apr 2016 18:29:54 +0200 Subject: [PATCH 3/5] Close file in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/FileTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/classes/FileTest.php b/test/classes/FileTest.php index 4c0e48369a..53e6486f9b 100644 --- a/test/classes/FileTest.php +++ b/test/classes/FileTest.php @@ -69,6 +69,7 @@ class FileTest extends PMATestCase $file->setDecompressContent(true); $file->open(); $this->assertEquals("TEST FILE\n", $file->read(100)); + $file->close(); } /** From 3dc44fd2fcee51ff5c1ff9ad0729bcd4ee786806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Apr 2016 18:30:57 +0200 Subject: [PATCH 4/5] Consistently return Message object as an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/File.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libraries/File.php b/libraries/File.php index 1166e4333a..263ba4b1bf 100644 --- a/libraries/File.php +++ b/libraries/File.php @@ -30,7 +30,7 @@ class File var $_content = null; /** - * @var string the error message + * @var Message the error message * @access protected */ var $_error_message = ''; @@ -220,7 +220,7 @@ class File if (! $this->isUploaded()) { $this->setName(null); - $this->_error_message = __('File was not an uploaded file.'); + $this->_error_message = Message::error(__('File was not an uploaded file.')); return false; } @@ -259,33 +259,33 @@ class File case 4: //UPLOAD_ERR_NO_FILE: break; case 1: //UPLOAD_ERR_INI_SIZE: - $this->_error_message = __( + $this->_error_message = Message::error(__( 'The uploaded file exceeds the upload_max_filesize directive in ' . 'php.ini.' - ); + )); break; case 2: //UPLOAD_ERR_FORM_SIZE: - $this->_error_message = __( + $this->_error_message = Message::error(__( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was ' . 'specified in the HTML form.' - ); + )); break; case 3: //UPLOAD_ERR_PARTIAL: - $this->_error_message = __( + $this->_error_message = Message::error(__( 'The uploaded file was only partially uploaded.' - ); + )); break; case 6: //UPLOAD_ERR_NO_TMP_DIR: - $this->_error_message = __('Missing a temporary folder.'); + $this->_error_message = Message::error(__('Missing a temporary folder.')); break; case 7: //UPLOAD_ERR_CANT_WRITE: - $this->_error_message = __('Failed to write file to disk.'); + $this->_error_message = Message::error(__('Failed to write file to disk.')); break; case 8: //UPLOAD_ERR_EXTENSION: - $this->_error_message = __('File upload stopped by extension.'); + $this->_error_message = Message::error(__('File upload stopped by extension.')); break; default: - $this->_error_message = __('Unknown error in file upload.'); + $this->_error_message = Message::error(__('Unknown error in file upload.')); } // end switch return false; @@ -359,7 +359,7 @@ class File * Returns possible error message. * * @access public - * @return string error message + * @return Message error message */ public function getError() { @@ -421,7 +421,7 @@ class File Util::userDir($GLOBALS['cfg']['UploadDir']) . PMA_securePath($name) ); if (! $this->isReadable()) { - $this->_error_message = __('File could not be read!'); + $this->_error_message = Message::error(__('File could not be read!')); $this->setName(null); return false; } @@ -471,9 +471,9 @@ class File if (@is_writable($tmp_subdir)) { // cannot create directory or access, point user to FAQ 1.11 - $this->_error_message = __( + $this->_error_message = Message::error(__( 'Error moving the uploaded file, see [doc@faq1-11]FAQ 1.11[/doc].' - ); + )); return false; } @@ -491,7 +491,7 @@ class File ); ob_end_clean(); if (! $move_uploaded_file_result) { - $this->_error_message = __('Error while moving uploaded file.'); + $this->_error_message = Message::error(__('Error while moving uploaded file.')); return false; } @@ -499,7 +499,7 @@ class File $this->isTemp(true); if (! $this->isReadable()) { - $this->_error_message = __('Cannot read uploaded file.'); + $this->_error_message = Message::error(__('Cannot read uploaded file.')); return false; } @@ -524,7 +524,7 @@ class File ob_end_clean(); if (! $file) { - $this->_error_message = __('File could not be read!'); + $this->_error_message = Message::error(__('File could not be read!')); return false; } From 00db766927803791eb64c4b6353ca50a433ac9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Apr 2016 18:31:56 +0200 Subject: [PATCH 5/5] Remove unused function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/import.lib.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 06bf334b12..d1186ee33e 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -47,23 +47,6 @@ function PMA_checkTimeout() } } -/** - * Detects what compression the file uses - * - * @param string $filepath filename to check - * - * @return string MIME type of compression, none for none - * @access public - */ -function PMA_detectCompression($filepath) -{ - $file = @fopen($filepath, 'rb'); - if (! $file) { - return false; - } - return PMA\libraries\Util::getCompressionMimeType($file); -} - /** * Runs query inside import buffer. This is needed to allow displaying * of last SELECT, SHOW or HANDLER results and similar nice stuff.