From fe2b9b14d31c06a089f99a438167ce143b8d0b6d Mon Sep 17 00:00:00 2001 From: cdujeu Date: Mon, 10 Nov 2014 21:12:03 +0100 Subject: [PATCH] Test if gzopen64 function exists for some versions of PHP compiled with large files support. Fix #690 --- core/src/core/classes/class.ConfService.php | 2 +- core/src/core/classes/pclzip.lib.php | 16 +++++++++++++--- core/src/core/tests/test.Zlib.php | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/src/core/classes/class.ConfService.php b/core/src/core/classes/class.ConfService.php index 810d62f6b4..57e4d5aea8 100644 --- a/core/src/core/classes/class.ConfService.php +++ b/core/src/core/classes/class.ConfService.php @@ -869,7 +869,7 @@ public function deleteRepositoryInst($repoId) public static function zipEnabled() { if(ConfService::getCoreConf("DISABLE_ZIP_BROWSING") === true) return false; - return (function_exists("gzopen")?true:false); + return ((function_exists("gzopen") || function_exists("gzopen64"))?true:false); } /** * Get the list of all "conf" messages diff --git a/core/src/core/classes/pclzip.lib.php b/core/src/core/classes/pclzip.lib.php index 2e32782dbf..9fd6c597a4 100644 --- a/core/src/core/classes/pclzip.lib.php +++ b/core/src/core/classes/pclzip.lib.php @@ -216,7 +216,7 @@ function PclZip($p_zipname) { // ----- Tests the zlib - if (!function_exists('gzopen')) + if (!function_exists('gzopen') && !function_exists('gzopen64')) { die('Abort '.basename(__FILE__).' : Missing zlib extensions'); } @@ -2811,7 +2811,12 @@ function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) // ----- Creates a compressed temporary file $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; - if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { + if(function_exists('gzopen64')){ + $v_file_compressed = @gzopen64($v_gzip_temp_name, "wb"); + }else{ + $v_file_compressed = @gzopen($v_gzip_temp_name, "wb"); + } + if ($v_file_compressed == 0) { fclose($v_file); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); @@ -4005,7 +4010,12 @@ function privExtractFileUsingTempFile(&$p_entry, &$p_options) } // ----- Open the temporary gz file - if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { + if(function_exists('gzopen64')){ + $v_src_file = @gzopen64($v_gzip_temp_name, 'rb'); + }else{ + $v_src_file = @gzopen($v_gzip_temp_name, 'rb'); + } + if ($v_src_file == 0) { @fclose($v_dest_file); $p_entry['status'] = "read_error"; PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); diff --git a/core/src/core/tests/test.Zlib.php b/core/src/core/tests/test.Zlib.php index 875f81d8af..7c3f02d3b6 100644 --- a/core/src/core/tests/test.Zlib.php +++ b/core/src/core/tests/test.Zlib.php @@ -28,10 +28,10 @@ */ class Zlib extends AbstractTest { - public function Zlib() { parent::AbstractTest("Zlib extension (ZIP)", "Extension enabled : ".(function_exists('gzopen')?"1":"0")); } + public function Zlib() { parent::AbstractTest("Zlib extension (ZIP)", "Extension enabled : ".((function_exists('gzopen')||function_exists('gzopen64'))?"1":"0")); } public function doTest() { - $this->testedParams["Zlib Enabled"] = (function_exists('gzopen')?"Yes":"No"); + $this->testedParams["Zlib Enabled"] = ((function_exists('gzopen')||function_exists('gzopen64'))?"Yes":"No"); $os = PHP_OS; /*if (stristr($os, "win")!==false && $this->testedParams["Zlib Enabled"]) { $this->failedLevel = "warning";