From f04feb78f835a3b38d9e05c844e7b9496055fc66 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Thu, 7 Oct 2010 10:11:37 +0000 Subject: [PATCH] Improved file identification by adding a magic signature test (0x1F,0x8B as the first two characters of the file) git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@61956 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Reader/Gnumeric.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Classes/PHPExcel/Reader/Gnumeric.php b/Classes/PHPExcel/Reader/Gnumeric.php index bf59fe4..9bcd3a1 100644 --- a/Classes/PHPExcel/Reader/Gnumeric.php +++ b/Classes/PHPExcel/Reader/Gnumeric.php @@ -196,6 +196,15 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } + // Read signature data (first 3 bytes) + $fh = fopen($pFilename, 'r'); + $data = fread($fh, 2); + fclose($fh); + + if ($data != chr(0x1F).chr(0x8B)) { + return false; + } + return true; }