Skip to content

Commit b21770c

Browse files
authored
Merge pull request #22 from risototh/master
Moved to RC8 of pear/OLE
2 parents 8fa6f64 + 1265890 commit b21770c

File tree

3 files changed

+4
-89
lines changed

3 files changed

+4
-89
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": "^7.1",
77
"ext-bcmath": "*",
88
"ext-mbstring": "*",
9-
"pear/ole": "^1.0.0RC5",
9+
"pear/ole": "^1.0.0RC8",
1010
"pear/pear-core-minimal": "^1.10",
1111
"symfony/yaml": "^4.1 || ^5.0",
1212
"ramsey/uuid": "^3.8 || ^4.0",

src/MAPI/OLE/Pear/DocumentFactory.php

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -22,94 +22,8 @@ public function createFromStream($stream): CompoundDocumentElement
2222
// PHP buffering appears to prevent us using this wrapper - sometimes fseek() is not called
2323
//$wrappedStreamUrl = StreamWrapper::wrapStream($stream, 'r');
2424

25-
$fh = $stream;
2625
$ole = new OLE();
27-
28-
{
29-
$ole->_file_handle = $fh;
30-
31-
$signature = fread($fh, 8);
32-
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
33-
return $ole->raiseError("File doesn't seem to be an OLE container.");
34-
}
35-
fseek($fh, 28);
36-
if (fread($fh, 2) != "\xFE\xFF") {
37-
// This shouldn't be a problem in practice
38-
return $ole->raiseError("Only Little-Endian encoding is supported.");
39-
}
40-
// Size of blocks and short blocks in bytes
41-
$ole->bigBlockSize = pow(2, $ole->_readInt2($fh));
42-
$ole->smallBlockSize = pow(2, $ole->_readInt2($fh));
43-
44-
// Skip UID, revision number and version number
45-
fseek($fh, 44);
46-
// Number of blocks in Big Block Allocation Table
47-
$bbatBlockCount = $ole->_readInt4($fh);
48-
49-
// Root chain 1st block
50-
$directoryFirstBlockId = $ole->_readInt4($fh);
51-
52-
// Skip unused bytes
53-
fseek($fh, 56);
54-
// Streams shorter than this are stored using small blocks
55-
$ole->bigBlockThreshold = $ole->_readInt4($fh);
56-
// Block id of first sector in Short Block Allocation Table
57-
$sbatFirstBlockId = $ole->_readInt4($fh);
58-
// Number of blocks in Short Block Allocation Table
59-
$sbbatBlockCount = $ole->_readInt4($fh);
60-
// Block id of first sector in Master Block Allocation Table
61-
$mbatFirstBlockId = $ole->_readSignedInt4($fh);
62-
// Number of blocks in Master Block Allocation Table
63-
$mbbatBlockCount = $ole->_readInt4($fh);
64-
$ole->bbat = array();
65-
66-
// Remaining 4 * 109 bytes of current block is beginning of Master
67-
// Block Allocation Table
68-
$mbatBlocks = array();
69-
for ($i = 0; $i < 109; $i++) {
70-
$mbatBlocks[] = $ole->_readSignedInt4($fh);
71-
}
72-
73-
// Read rest of Master Block Allocation Table (if any is left)
74-
$pos = $ole->_getBlockOffset($mbatFirstBlockId);
75-
for ($i = 0; $i < $mbbatBlockCount; $i++) {
76-
fseek($fh, $pos);
77-
for ($j = 0; $j < $ole->bigBlockSize / 4 - 1; $j++) {
78-
$mbatBlocks[] = $ole->_readInt4($fh);
79-
}
80-
// Last block id in each block points to next block
81-
$pos = $ole->_getBlockOffset($ole->_readInt4($fh));
82-
}
83-
84-
// Read Big Block Allocation Table according to chain specified by
85-
// $mbatBlocks
86-
for ($i = 0; $i < $bbatBlockCount; $i++) {
87-
$pos = $ole->_getBlockOffset($mbatBlocks[$i]);
88-
fseek($fh, $pos);
89-
for ($j = 0 ; $j < $ole->bigBlockSize / 4; $j++) {
90-
$ole->bbat[] = $ole->_readSignedInt4($fh);
91-
}
92-
}
93-
94-
// Read short block allocation table (SBAT)
95-
$ole->sbat = array();
96-
$shortBlockCount = $sbbatBlockCount * $ole->bigBlockSize / 4;
97-
$sbatFh = $ole->getStream($sbatFirstBlockId);
98-
if (!$sbatFh) {
99-
// Avoid an infinite loop if ChainedBlockStream.php somehow is
100-
// missing
101-
return false;
102-
}
103-
for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) {
104-
$ole->sbat[$blockId] = $ole->_readSignedInt4($sbatFh);
105-
}
106-
fclose($sbatFh);
107-
108-
$ole->_readPpsWks($directoryFirstBlockId);
109-
110-
}
111-
112-
26+
$ole->readStream($stream);
11327

11428
return new DocumentElement($ole, $ole->root);
11529
}

src/MAPI/Property/PropertyStore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ protected function parseNameId($obj)
137137
$prop = '';
138138
if ($named) {
139139
$str_off = unpack('V', $rawProp)[1];
140-
$len = unpack('V', substr($namesData, $str_off, 4))[1];
140+
if (strlen($namesData) - $str_off < 4) continue; // not sure with this, but at least it will not read outside the bounds and crash
141+
$len = unpack('V', substr($namesData, $str_off, 4))[1];
141142
$data = substr($namesData, $str_off + 4, $len);
142143
$prop = mb_convert_encoding($data, 'UTF-8', 'UTF-16LE');
143144
}

0 commit comments

Comments
 (0)