From 3a62efd6408b29c3528af08cb5797b284232281f Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 23 May 2013 15:09:28 -0500
Subject: [PATCH] Fix md5 hash on windows platforms

The installer compares the md5 of the on-disk sql install file with the
signature file shipped alongside. If the signatures do not match, it will
refuse to install osTicket. On Windows(TM) platforms, PHP will automatically
translate newlines to Windows newlines (CRLF), which will corrupt the MD5
hash of the file.

This patch opens the file in binary mode explicitly to prevent the automatic
conversion.
---
 setup/inc/class.installer.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/setup/inc/class.installer.php b/setup/inc/class.installer.php
index 21ac30f9b..8372a6e23 100644
--- a/setup/inc/class.installer.php
+++ b/setup/inc/class.installer.php
@@ -113,10 +113,14 @@ class Installer extends SetupWizard {
         $debug = true; //XXX:Change it to true to show SQL errors.
 
         //Last minute checks.
-        if(!file_exists($schemaFile))
+        if(!file_exists($schemaFile) || !($fp = fopen($schemaFile, 'rb')))
             $this->errors['err']='Internal Error - please make sure your download is the latest (#1)';
-        elseif(!($signature=trim(file_get_contents("$schemaFile.md5"))) || strcasecmp($signature, md5_file($schemaFile)))
-            $this->errors['err']='Unknown or invalid schema signature ('.$signature.' .. '.md5_file($schemaFile).')';
+        elseif(
+                !($signature=trim(file_get_contents("$schemaFile.md5")))
+                || !($hash=md5(fread($fp, filesize($schemaFile))))
+                || strcasecmp($signature, $hash))
+            $this->errors['err']='Unknown or invalid schema signature ('
+                .$signature.' .. '.$hash.')';
         elseif(!file_exists($this->getConfigFile()) || !($configFile=file_get_contents($this->getConfigFile())))
             $this->errors['err']='Unable to read config file. Permission denied! (#2)';
         elseif(!($fp = @fopen($this->getConfigFile(),'r+')))
-- 
GitLab