From bc7028ae4e72643a6feae86325ba44fc14364484 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Wed, 29 Apr 2015 22:23:14 +0100 Subject: [PATCH] Modified XEE security scan to handle UTF-16 charset, and added unit tests for the security scan --- Classes/PHPExcel/Reader/Abstract.php | 3 +- .../PHPExcel/Reader/XEEValidatorTest.php | 55 ++++++++++++++++++ .../Reader/XEETestInvalidUTF-16.xml | Bin 0 -> 276 bytes .../Reader/XEETestInvalidUTF-16BE.xml | Bin 0 -> 278 bytes .../Reader/XEETestInvalidUTF-16LE.xml | Bin 0 -> 278 bytes .../Reader/XEETestInvalidUTF-8.xml | 8 +++ .../rawTestData/Reader/XEETestValidUTF-16.xml | Bin 0 -> 176 bytes .../Reader/XEETestValidUTF-16BE.xml | Bin 0 -> 178 bytes .../Reader/XEETestValidUTF-16LE.xml | Bin 0 -> 178 bytes .../rawTestData/Reader/XEETestValidUTF-8.xml | 4 ++ 10 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 unitTests/Classes/PHPExcel/Reader/XEEValidatorTest.php create mode 100644 unitTests/rawTestData/Reader/XEETestInvalidUTF-16.xml create mode 100644 unitTests/rawTestData/Reader/XEETestInvalidUTF-16BE.xml create mode 100644 unitTests/rawTestData/Reader/XEETestInvalidUTF-16LE.xml create mode 100644 unitTests/rawTestData/Reader/XEETestInvalidUTF-8.xml create mode 100644 unitTests/rawTestData/Reader/XEETestValidUTF-16.xml create mode 100644 unitTests/rawTestData/Reader/XEETestValidUTF-16BE.xml create mode 100644 unitTests/rawTestData/Reader/XEETestValidUTF-16LE.xml create mode 100644 unitTests/rawTestData/Reader/XEETestValidUTF-8.xml diff --git a/Classes/PHPExcel/Reader/Abstract.php b/Classes/PHPExcel/Reader/Abstract.php index fdbd2669..0036dff9 100644 --- a/Classes/PHPExcel/Reader/Abstract.php +++ b/Classes/PHPExcel/Reader/Abstract.php @@ -235,7 +235,8 @@ abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader */ public function securityScan($xml) { - if (strpos($xml, 'getMockForAbstractClass('PHPExcel_Reader_Abstract'); + $expectedResult = 'FAILURE: Should throw an Exception rather than return a value'; + $result = $reader->securityScanFile($filename); + $this->assertEquals($expectedResult, $result); + } + + public function providerInvalidXML() + { + $tests = []; + foreach(glob('rawTestData/Reader/XEETestInvalid*.xml') as $file) { + $tests[] = [realpath($file), true]; + } + return $tests; + } + + /** + * @dataProvider providerValidXML + */ + public function testValidXML($filename, $expectedResult) + { + $reader = $this->getMockForAbstractClass('PHPExcel_Reader_Abstract'); + $result = $reader->securityScanFile($filename); + $this->assertEquals($expectedResult, $result); + } + + public function providerValidXML() + { + $tests = []; + foreach(glob('rawTestData/Reader/XEETestValid*.xml') as $file) { + $tests[] = [realpath($file), file_get_contents($file)]; + } + return $tests; + } + +} diff --git a/unitTests/rawTestData/Reader/XEETestInvalidUTF-16.xml b/unitTests/rawTestData/Reader/XEETestInvalidUTF-16.xml new file mode 100644 index 0000000000000000000000000000000000000000..94eaedfc2aec6c1eb2e723c914acf0afcdbbfd65 GIT binary patch literal 276 zcmX|*O%K697=)iIiT|*A5Dut|gO57+NL-NMAmSj}h@{#?MfmfW?v`w_?`G$jnfLu+ zz=$VTVhj%=Ze(0YNf_eMp@pw$q$Hg5A4*L)TXoBZ8BI}L%VgX+N)2_#HY2j!OYTg> zh=2-Zbyk_MWGw%V6;tKk#HaEb_Lebvxs%gV7Gmd?H`>>i<|!j(t?5z^#dHn7Jg1eE VobPa_Cug0S&FIr8_G$n7gD--qCxrk2 literal 0 HcmV?d00001 diff --git a/unitTests/rawTestData/Reader/XEETestInvalidUTF-16BE.xml b/unitTests/rawTestData/Reader/XEETestInvalidUTF-16BE.xml new file mode 100644 index 0000000000000000000000000000000000000000..1d186ff443435bec745501c2d7bfc81271e4c3c5 GIT binary patch literal 278 zcmX|*!4APd6h+UL#6JuRVS(CMP;G)rY>;3fVjOWMPaI@)wJxh9`M$8B-myvT35$cYuC$j8EhD?Ny zM}s;pO%`mJ%W-6@Zll?$POjI+J3Go+a-{53OY6C+<%FNF%xW?h UJLHVj*`aM66S~ztga3T*3-^U44*&oF literal 0 HcmV?d00001 diff --git a/unitTests/rawTestData/Reader/XEETestInvalidUTF-16LE.xml b/unitTests/rawTestData/Reader/XEETestInvalidUTF-16LE.xml new file mode 100644 index 0000000000000000000000000000000000000000..c3913f71bb84e44fb3659848c69c0434945a2642 GIT binary patch literal 278 zcmX|*!4APd6h+UL#6JuRVS(CMQ0;f@4L_Ep3laer{#gIOZs!@_~)qkio;bzkVdlvLWjaU&_E+gk6BGesQPh{DT44DWY zj|O#In#|cSljF!%-A1!hom{VzWsF|sDd>Q;*rnx-c6OAt + +]> + + + test: (&x0;) + \ No newline at end of file diff --git a/unitTests/rawTestData/Reader/XEETestValidUTF-16.xml b/unitTests/rawTestData/Reader/XEETestValidUTF-16.xml new file mode 100644 index 0000000000000000000000000000000000000000..6473fe6b6382c7f6993f3c9f0187bd0636613a98 GIT binary patch literal 176 zcmYL?I}Ug^iD-dB + + test: Valid + \ No newline at end of file