From 789a643263f905d054969c94df842819fe1b5c11 Mon Sep 17 00:00:00 2001 From: kajal-techhighway Date: Wed, 6 Apr 2016 18:18:46 +0530 Subject: [PATCH 1/2] Throw InvalidArgumentException in case getint4d fails --- Classes/PHPExcel/Shared/OLERead.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Classes/PHPExcel/Shared/OLERead.php b/Classes/PHPExcel/Shared/OLERead.php index 6b15d9700..51e2c6d6d 100644 --- a/Classes/PHPExcel/Shared/OLERead.php +++ b/Classes/PHPExcel/Shared/OLERead.php @@ -306,6 +306,18 @@ private static function getInt4d($data, $pos) // FIX: represent numbers correctly on 64-bit system // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334 // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems + if(!isset($data[$pos + 3])){ + $error_message = 'EXCEPTION (InvalidBlockException) :: CORRUPT BLOCKS IN XLS FILE'."\nCallStack: \n"; + foreach(debug_backtrace() as $ik=>$kk){ + $message = ''; + foreach($kk as $ikk=>$kkk){ + if($ikk=='object' || $ikk=='args' || $ikk=='type') continue; + $message .= ''.$ikk.'=>['.$kkk.']'." "; + } + if(!empty($message)) $error_message.=$message."\n"; + } + throw new InvalidArgumentException($error_message); + }//if $_or_24 = ord($data[$pos + 3]); if ($_or_24 >= 128) { // negative number From 319ae1271d86ec9eb4ac13b12632788c4968454a Mon Sep 17 00:00:00 2001 From: kajal-techhighway Date: Thu, 7 Apr 2016 19:37:24 +0530 Subject: [PATCH 2/2] modified file OlERead to throw exception when we get corrupted .xls or .xlsx file ( when OLERead fails to detect size of cell blocks and goes in infinite loop) : changed code according to PSR2 --- Classes/PHPExcel/Shared/OLERead.php | 34 +++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Classes/PHPExcel/Shared/OLERead.php b/Classes/PHPExcel/Shared/OLERead.php index 51e2c6d6d..116b07d10 100644 --- a/Classes/PHPExcel/Shared/OLERead.php +++ b/Classes/PHPExcel/Shared/OLERead.php @@ -306,18 +306,34 @@ private static function getInt4d($data, $pos) // FIX: represent numbers correctly on 64-bit system // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334 // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems - if(!isset($data[$pos + 3])){ - $error_message = 'EXCEPTION (InvalidBlockException) :: CORRUPT BLOCKS IN XLS FILE'."\nCallStack: \n"; - foreach(debug_backtrace() as $ik=>$kk){ + + // Handling Errors : Dependancy of code on $pos of $data. Hence added a check to make sure the block is valid/readable. + // Throwing Exception incase of any error. + + if (!isset($data[$pos + 3])) { + //String $error_message : Declaration only once + $error_message = 'EXCEPTION (InvalidBlockException) :: CORRUPT BLOCKS IN XLS FILE'."\nCallStack:\n"; + + foreach (debug_backtrace() as $arr_info_element) { + //String $message : Redeclaration $message = ''; - foreach($kk as $ikk=>$kkk){ - if($ikk=='object' || $ikk=='args' || $ikk=='type') continue; - $message .= ''.$ikk.'=>['.$kkk.']'." "; + + foreach ($arr_info_element as $info_property => $info_value) { + // ignoring the properties [object], [args] and [type] as it causes essay effect while printing error message. + if ($info_property == 'object' || $info_property == 'args' || $info_property == 'type') { + continue; + } + + $message .= $info_property.'=>['.$info_value.'] '; + } + + //add error message + if (!empty($message)) { + $error_message .= $message."\n"; } - if(!empty($message)) $error_message.=$message."\n"; } - throw new InvalidArgumentException($error_message); - }//if + throw new InvalidArgumentException($error_message); + } $_or_24 = ord($data[$pos + 3]); if ($_or_24 >= 128) { // negative number