From 08b4456641f09f142dd5c2b7e72dc6490adc2d2f Mon Sep 17 00:00:00 2001 From: bayzhanov Date: Sun, 7 Oct 2018 18:38:13 +1100 Subject: [PATCH] Xls file threw exception during open by Xls reader Ignore some exception in property, if stream is empty Fixes #402 Fixes #659 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Shared/OLERead.php | 5 +--- tests/PhpSpreadsheetTests/Reader/XlsTest.php | 20 +++++++++++++ .../Shared/OLEReadTest.php | 28 ++++++++++++++++++ tests/data/Reader/XLS/sample.xls | Bin 0 -> 5109 bytes tests/data/Shared/OLERead/document | 0 tests/data/Shared/OLERead/summary | 0 tests/data/Shared/OLERead/wrkbook | Bin 0 -> 3061 bytes 8 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/PhpSpreadsheetTests/Reader/XlsTest.php create mode 100644 tests/PhpSpreadsheetTests/Shared/OLEReadTest.php create mode 100644 tests/data/Reader/XLS/sample.xls create mode 100755 tests/data/Shared/OLERead/document create mode 100755 tests/data/Shared/OLERead/summary create mode 100755 tests/data/Shared/OLERead/wrkbook diff --git a/CHANGELOG.md b/CHANGELOG.md index 963f01d8..8b1fcbd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Sheet title can contain exclamation mark - [#325](https://github.com/PHPOffice/PhpSpreadsheet/issues/325) +- Xls file cause the exception during open by Xls reader - [#402](https://github.com/PHPOffice/PhpSpreadsheet/issues/402) ## [1.4.1] - 2018-09-30 diff --git a/src/PhpSpreadsheet/Shared/OLERead.php b/src/PhpSpreadsheet/Shared/OLERead.php index 57554117..3af39700 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -326,10 +326,7 @@ class OLERead */ private static function getInt4d($data, $pos) { - if (trim($data) == '') { - // No data provided - throw new ReaderException('Parameter data is empty.'); - } elseif ($pos < 0) { + if ($pos < 0) { // Invalid position throw new ReaderException('Parameter pos=' . $pos . ' is invalid.'); } diff --git a/tests/PhpSpreadsheetTests/Reader/XlsTest.php b/tests/PhpSpreadsheetTests/Reader/XlsTest.php new file mode 100644 index 00000000..f629fed1 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/XlsTest.php @@ -0,0 +1,20 @@ +load($filename); + self::assertEquals('Title', $spreadsheet->getSheet(0)->getCell('A1')->getValue()); + } +} diff --git a/tests/PhpSpreadsheetTests/Shared/OLEReadTest.php b/tests/PhpSpreadsheetTests/Shared/OLEReadTest.php new file mode 100644 index 00000000..a004c4ae --- /dev/null +++ b/tests/PhpSpreadsheetTests/Shared/OLEReadTest.php @@ -0,0 +1,28 @@ +read('./data/Reader/XLS/sample.xls'); + self::assertEquals( + file_get_contents($dataDir . 'wrkbook'), + $ole->getStream($ole->wrkbook) + ); + self::assertEquals( + file_get_contents($dataDir . 'summary'), + $ole->getStream($ole->summaryInformation) + ); + self::assertEquals( + file_get_contents($dataDir . 'document'), + $ole->getStream($ole->documentSummaryInformation) + ); + } +} diff --git a/tests/data/Reader/XLS/sample.xls b/tests/data/Reader/XLS/sample.xls new file mode 100644 index 0000000000000000000000000000000000000000..65fcba55a8dcda0ea01ad60866092a231086643f GIT binary patch literal 5109 zcmeH~&u>&!6vxkd^Jd!V&zb2D1i?N8sUQMP4QLDq2pA$I$d71ZT$Iv6LuqSig)RuQ zac>kbv(qIT6B9Q;B3&9Yi6;C3R{sJQlCV&opYOdh%s{7sxG^Gc=G^=4dEay2x#!$_ z&UruolwbV%+f~2XBiAlV+5IGInL2*Jy~tfTvydB&?wzxt(!#+V;N7&p|7pRnYU$YG@7g0@Me^&|2t4XdSd3dI{P9^+PX18=+0mE6`@>RcH&e z6?zt%>UaJ>yU#Y`#Z206wU-t0UF_c(Xh-bCuZzLBmG@rW@VXw6>putw@a7NPCzn5~ z9QSmvhZ8(*!!}|6-qY3gRh?FWWrE{qbcU#Mj(*YYO|!d6461r9#Nulij{nD#@nxGv z_~rPTwGsYl<_GRpf@SB#wXB*-(?8-nf>d$=scHiwj zi@tY$_k7}4m0!^_LmUhg&zA60%kVqkH<~A02CtL!F#dD<&HNct3Uf)U(kP=j4mU*^ zsL~YaiyCmVu&_W^v{EUt(%=~RxNK$cWBd~MHpaND35#wn%?XH+eqyVI2}W{d{d3B^w+|Y_MF04_Z`$#+ZJrWY?};GXOSNf-%S+DmfanJ9qBb_3PK|i!icW zF_oy#7c;Ie6eHJn6`Nd-Lay&Frjt+c+K-VGOb5p}%cJ~e?VCXU38EF$r8yk@2`@35O4wQ)$EyxLkDr^uN%bG30~ zk@dIL#%U^}D^0a=hS++gxi)U1#{RhOea)=rR-yJhYgxNdhi_q(H(F}XTgl1w<2H1z z*SDQq9oETrkhiDm^ywsrAL^{lmm{D5Qa8@CM~8Z9&kJ~Cy1h2;;*8Y4znfTkwQl`A z)B<0w^!VmbwE|ZVIF~I1ohF_e1oIDgQOLRD>cMsd@NwKdfzzY#O$Y6zoFLnrBBqa1 zt&ZDy0HZGZOxkISZHUn+_#?#pS^6nZ=Mh(x5-=+}XULA(yLJNRI#>b4O1rVUM!?P? zvzPuPRmL`=#&$Mx6sqD0k>xZWw0#x1(96AHJ2?C*#2hSZ56e1ehmn&7)5u{# zy;sH>O**yJep9ylX47kMJ91q`CEWA-32@jJ$2K z-Zn>pPNInSTDIbXxW9jocfne^7N7*Fnv0Jx*9;q5=VG=Z+Va5RKHPbSw<3yrj-lc- zKP^k5L72gJt=dna%J4Q|q_%x1BS*>hbHGNNUADyNsgE(ATq51QBfJ`&PV)go zbBI#dDQ5`gec~g;UssXY6tieE@X>AsQ+0X=f|j#hmFmcIHV& nRTp*hH5G;WB2tVc2viqZwMT5nfuBQ}iHh^QGCk<7kGa1Ao=w)L literal 0 HcmV?d00001 diff --git a/tests/data/Shared/OLERead/document b/tests/data/Shared/OLERead/document new file mode 100755 index 00000000..e69de29b diff --git a/tests/data/Shared/OLERead/summary b/tests/data/Shared/OLERead/summary new file mode 100755 index 00000000..e69de29b diff --git a/tests/data/Shared/OLERead/wrkbook b/tests/data/Shared/OLERead/wrkbook new file mode 100755 index 0000000000000000000000000000000000000000..ad344aa550e1c84f4fc61e987052dc0c14479a55 GIT binary patch literal 3061 zcmds(&2Lmy7{;G_=XN?X?R>UVL^NE2N)$nw8qgRO5HUpBR9g}grI8r4`L|aUjdf#lsrnfMh{?DzUf7e@XcEazbH>*40|IhkB zv4z*Ud_JYadc0%)U-kOOPvc+T1^?PE`23FeEUPkLE$i=U^}+rJ`xX7->hAT`R4?ym zRuTAt9rT%9^dS+fLe!|4zTl@3ACFlvpA<4I+Q7Nz^obr)knRP2kVQ#s*ze ztyZGeNCRkFZSW251ic!_Z8O+(w#=rt=PWoIHVY)jYr{{HmRiV33odq(c1t6TL?i7s zdeHW?cp8{*v~=gr9Rbit3&jXOo|bzW+T7gK`ue)Q4h)smuI+F^;2N=38Fp9(fg}Fmv<*wW!p)nu;c)?H>Dw-_rjWf zwnI)Qt?67h)bIXfs%6)k%pAH`O65?YZug~fMj73!q;jN4hx${wM?JdLo61?v)?2w$ z?p3e8>Y6V{JojtqcwTwk?ZOvS(A`2h-lx88az8$I`&(2|VHdxol9sysDXXmW<Oj?_KLU7Mb7kjE%ICeFyr1ni<(ueQKXCLr#bUi>6buV zfzEEjK%EK&qngmix`6T^s(?jN6sv0*>>8ZY^k3?Tj&W)nXCX&n5pD>V-F!}GI=s;H z-qs2B?J@2XU`J@*bnS6q``~5ZA+vaa+*>_90%qa+I^^Ku@E9s9 zUKD0n6FC?+6nst;OO$*bbgXC1#~Q~+3x0(vO%d899R=yJUpsy5-uTzi&4DmotgEzB za6ERD|2A$lw|J+RZxPwP6jrck(k#BmjIYqnp_!#MzpS@l4YA$Yq6;W?W7A;Qh{5Kz z^ju-CH?TgCy{wL>jDDY!rGe8KymQl1H1T;{g0j2eVlYS(A$DSVk3`hoFkJA*S;D9imCuxXc9 zUs+G-XIn<0?eroP-jbs(2~o(>MKwel40jNvEyR?rp&DSU1cJpn?DmoEg(y6Ntuja! z?T6s3;C_`^ACo>SiTUme;oT@Z&xfH_pz>j7?+ka2icI3zq<_VsVVDUuLzZB^uN|Y#xSSXDo-nR-jw?h&2iPGR`b?iszlF J