From 4b4831be07249743364a7335178fb44b4b3eeca7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 16 Nov 2016 14:17:43 +0100 Subject: [PATCH] Catch some invalid parameter (may come from damaged file) and throw exception. (#39) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/PhpSpreadsheet/Shared/OLERead.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PhpSpreadsheet/Shared/OLERead.php b/src/PhpSpreadsheet/Shared/OLERead.php index 63bff33c..05f1415f 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -302,6 +302,14 @@ class OLERead */ private static function getInt4d($data, $pos) { + if (trim($data) == '') { + // No data provided + throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('Parameter data is empty.'); + } elseif ($pos < 0) { + // Invalid position + throw new \PhpOffice\PhpSpreadsheet\Reader\Exception('Parameter pos=' . $pos . ' is invalid.'); + } + $len = strlen($data); if ($len < $pos + 4) { $data .= str_repeat("\0", $pos + 4 - $len);