From 2f9689b8f80408a39f5b3c96dbcd65b7396f8e67 Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Thu, 1 Aug 2013 09:42:52 +1200 Subject: [PATCH 1/3] FIX Flush on memory exhaustion and headers sent --- core/startup/ErrorControlChain.php | 24 +++++++++++++++++++++ core/startup/ParameterConfirmationToken.php | 9 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/startup/ErrorControlChain.php b/core/startup/ErrorControlChain.php index dc32257e7..4ac510cbb 100644 --- a/core/startup/ErrorControlChain.php +++ b/core/startup/ErrorControlChain.php @@ -74,9 +74,33 @@ class ErrorControlChain { return $error && ($error['type'] & self::$fatal_errors) != 0; } + protected function lastErrorWasMemoryExhaustion() { + $error = error_get_last(); + $message = $error ? $error['message'] : ''; + return stripos($message, 'memory') !== false && stripos($message, 'exhausted') !== false; + } + + static $transtable = array( + 'k' => 1024, + 'm' => 1048576, + 'g' => 1073741824 + ); + + protected function translateMemstring($memString) { + $char = strtolower(substr($memString, -1)); + $fact = isset(self::$transtable[$char]) ? self::$transtable[$char] : 1; + return ((int)$memString) * $fact; + } + public function handleFatalError() { if ($this->handleFatalErrors && $this->suppression) { if ($this->lastErrorWasFatal()) { + if ($this->lastErrorWasMemoryExhaustion()) { + // Bump up memory limit by an arbitrary 10% / 10MB (whichever is bigger) since we've run out + $cur = $this->translateMemstring(ini_get('memory_limit')); + if ($cur != -1) ini_set('memory_limit', $cur + max(round($cur*0.1), 10000000)); + } + $this->error = true; $this->step(); } diff --git a/core/startup/ParameterConfirmationToken.php b/core/startup/ParameterConfirmationToken.php index 21364f871..fe85d293f 100644 --- a/core/startup/ParameterConfirmationToken.php +++ b/core/startup/ParameterConfirmationToken.php @@ -94,7 +94,14 @@ class ParameterConfirmationToken { $location = "$proto://" . $host . BASE_URL . $url . ($params ? '?'.http_build_query($params) : ''); // And redirect - header('location: '.$location, true, 302); + if (headers_sent()) { + echo " + + +You are being redirected. If you are not redirected soon, click here to continue the flush +"; + } + else header('location: '.$location, true, 302); die; } } From 60a95cbe77ec06c3326570440b22f36ceff38920 Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Mon, 5 Aug 2013 09:14:10 +1200 Subject: [PATCH 2/3] FIX Token redirect where in IIS a / needs adding between host & url --- core/startup/ParameterConfirmationToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/startup/ParameterConfirmationToken.php b/core/startup/ParameterConfirmationToken.php index fe85d293f..288488b6b 100644 --- a/core/startup/ParameterConfirmationToken.php +++ b/core/startup/ParameterConfirmationToken.php @@ -91,7 +91,7 @@ class ParameterConfirmationToken { unset($params['url']); // Join them all together into the original URL - $location = "$proto://" . $host . BASE_URL . $url . ($params ? '?'.http_build_query($params) : ''); + $location = "$proto://" . $host . '/' . ltrim(BASE_URL, '/') . $url . ($params ? '?'.http_build_query($params) : ''); // And redirect if (headers_sent()) { From 15406dd559d55c3c1a492f3ee31f60ba27ed83a2 Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Mon, 5 Aug 2013 14:58:06 +1200 Subject: [PATCH 3/3] FIX Constants magic_quotes needs function from Core --- core/Constants.php | 7 +++++++ core/Core.php | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/Constants.php b/core/Constants.php index 1895f56ab..2eb501d0b 100644 --- a/core/Constants.php +++ b/core/Constants.php @@ -46,6 +46,13 @@ foreach($envFiles as $envFile) { /////////////////////////////////////////////////////////////////////////////// // GLOBALS AND DEFINE SETTING +function stripslashes_recursively(&$array) { + foreach($array as $k => $v) { + if(is_array($v)) stripslashes_recursively($array[$k]); + else $array[$k] = stripslashes($v); + } +} + /** * A blank HTTP_HOST value is used to detect command-line execution. * We update the $_SERVER variable to contain data consistent with the rest of the application. diff --git a/core/Core.php b/core/Core.php index 5d2d2308b..b67319226 100755 --- a/core/Core.php +++ b/core/Core.php @@ -153,13 +153,6 @@ function project() { return $project; } -function stripslashes_recursively(&$array) { - foreach($array as $k => $v) { - if(is_array($v)) stripslashes_recursively($array[$k]); - else $array[$k] = stripslashes($v); - } -} - /** * @see i18n::_t() */