From 33d49eda35b9b1f4a4d5fb2d7ff73f1bc0966ad3 Mon Sep 17 00:00:00 2001 From: alius Date: Tue, 19 Sep 2017 13:29:17 +0300 Subject: [PATCH 1/2] Fixed Segmentation fault when reading big xlsx files. --- Classes/PHPExcel/Reader/Excel2007.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 1932df4b6..037245a73 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -642,7 +642,13 @@ public function load($pFilename) // reverse $docSheet->setTitle((string) $eleSheet["name"], false); $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; - $xmlSheet = simplexml_load_string($this->securityScan($this->getFromZipArchive($zip, "$dir/$fileWorksheet")), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions()); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); + $xmlString = $this->securityScan($this->getFromZipArchive($zip, "$dir/$fileWorksheet")); + if (!xml_parse($parser = xml_parser_create(), $xmlString)) { + throw new PHPExcel_Reader_Exception(xml_error_string(xml_get_error_code($parser))); + } + + $xmlSheet = simplexml_load_string($xmlString, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions()); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); + $sharedFormulas = array(); From 58702c8529bef6412c7374154817c5869deff6a8 Mon Sep 17 00:00:00 2001 From: alius Date: Tue, 19 Sep 2017 14:11:52 +0300 Subject: [PATCH 2/2] Free up memory --- Classes/PHPExcel/Reader/Excel2007.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 037245a73..f99df1522 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -644,8 +644,11 @@ public function load($pFilename) $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; $xmlString = $this->securityScan($this->getFromZipArchive($zip, "$dir/$fileWorksheet")); if (!xml_parse($parser = xml_parser_create(), $xmlString)) { - throw new PHPExcel_Reader_Exception(xml_error_string(xml_get_error_code($parser))); + $errorString = xml_error_string(xml_get_error_code($parser)); + xml_parser_free($parser); + throw new PHPExcel_Reader_Exception($errorString); } + xml_parser_free($parser); $xmlSheet = simplexml_load_string($xmlString, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions()); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");