Skip to content

Commit 7a7634f

Browse files
author
Mark Baker
committed
Only read first 8 bytes of a file when validating, rather than load the entire file into memory at that point
1 parent b880b5f commit 7a7634f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Classes/PHPExcel/Shared/OLERead.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@ public function read($sFileName)
8080
throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
8181
}
8282

83-
// Get the file data
84-
$this->data = file_get_contents($sFileName);
83+
// Get the file identifier
84+
// Don't bother reading the whole file until we know it's a valid OLE file
85+
$this->data = file_get_contents($sFileName, FALSE, NULL, 0, 8);
8586

8687
// Check OLE identifier
87-
if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) {
88+
if ($this->data != self::IDENTIFIER_OLE) {
8889
throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
8990
}
9091

92+
// Get the file data
93+
$this->data = file_get_contents($sFileName);
94+
9195
// Total number of sectors used for the SAT
9296
$this->numBigBlockDepotBlocks = self::_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
9397

0 commit comments

Comments
 (0)