diff --git a/application/themehandler.class.inc.php b/application/themehandler.class.inc.php index 52073bea3..25c5b6734 100644 --- a/application/themehandler.class.inc.php +++ b/application/themehandler.class.inc.php @@ -699,8 +699,9 @@ CSS; /** * @since 3.0.0 N°2982 - * Extract the signature for a generated CSS file. The signature MUST be alone one line immediately - * followed (on the next line) by the === SIGNATURE END === pattern + * Extract the signature for a generated CSS file. + * The signature MUST be alone one line immediately followed (on the next line) by the === SIGNATURE END === pattern + * The signature MUST be in the first 100th lines of the file. * * Note the signature can be place anywhere in the CSS file (obviously inside a CSS comment !) but the * function will be faster if the signature is at the beginning of the file (since the file is scanned from the start) @@ -711,6 +712,7 @@ CSS; */ public static function GetSignature($sFilepath) { + $iCount = 0; $sPreviousLine = ''; $hFile = @fopen($sFilepath, "r"); if ($hFile !== false) @@ -718,10 +720,11 @@ CSS; $sLine = ''; do { + $iCount++; $sPreviousLine = $sLine; $sLine = rtrim(fgets($hFile)); // Remove the trailing \n } - while (($sLine !== false) && ($sLine != '=== SIGNATURE END ===')); + while (($sLine !== false) && ($sLine != '=== SIGNATURE END ===') && ($iCount <= 100)); fclose($hFile); } return $sPreviousLine; diff --git a/test/application/ThemeHandlerTest.php b/test/application/ThemeHandlerTest.php index 2e6b6caf3..9fda00021 100644 --- a/test/application/ThemeHandlerTest.php +++ b/test/application/ThemeHandlerTest.php @@ -223,6 +223,13 @@ class ThemeHandlerTest extends ItopTestCase return @mkdir($dir); } + public function testGetSignatureWithFileWithoutSignature() + { + $sTmpFile = tempnam(sys_get_temp_dir(), "sig"); + file_put_contents($sTmpFile,"ffff"); + $this->assertEquals("", ThemeHandler::GetSignature($sTmpFile)); + } + public function testGetSignature() { $sSig = ThemeHandler::GetSignature(APPROOT.'test/application/theme-handler/expected/themes/basque-red/main.css');