Only read first 8 bytes of a file when validating, rather than load the entire file into memory at that point

This commit is contained in:
Mark Baker 2013-05-24 12:57:42 +01:00
parent b880b5ff9d
commit 7a7634fba6
1 changed files with 7 additions and 3 deletions

View File

@ -80,14 +80,18 @@ class PHPExcel_Shared_OLERead {
throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable."); throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
} }
// Get the file data // Get the file identifier
$this->data = file_get_contents($sFileName); // Don't bother reading the whole file until we know it's a valid OLE file
$this->data = file_get_contents($sFileName, FALSE, NULL, 0, 8);
// Check OLE identifier // Check OLE identifier
if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) { if ($this->data != self::IDENTIFIER_OLE) {
throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file'); throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
} }
// Get the file data
$this->data = file_get_contents($sFileName);
// Total number of sectors used for the SAT // Total number of sectors used for the SAT
$this->numBigBlockDepotBlocks = self::_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS); $this->numBigBlockDepotBlocks = self::_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);