@@ -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 }
0 commit comments