From 14f187db4c84f819f2424049c6b0c857c1a85c25 Mon Sep 17 00:00:00 2001 From: hfig Date: Mon, 16 Jul 2018 16:15:45 +1000 Subject: [PATCH 1/2] Compat fix warning on end() end() operates on a reference requires a variable be passed not a function result. --- OLE.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OLE.php b/OLE.php index e3cc740..e9631bf 100755 --- a/OLE.php +++ b/OLE.php @@ -241,7 +241,8 @@ function getStream($blockIdOrPps) // in OLE_ChainedBlockStream::stream_open(). // Object is removed from self::$instances in OLE_Stream::close(). $GLOBALS['_OLE_INSTANCES'][] = $this; - $instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES'])); + $keys = array_keys($GLOBALS['_OLE_INSTANCES']); + $instanceId = end($keys); $path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId; if (is_a($blockIdOrPps, 'OLE_PPS')) { From 412b532a33755f8c6551ce7193258061b25b4531 Mon Sep 17 00:00:00 2001 From: hfig Date: Mon, 16 Jul 2018 16:18:24 +1000 Subject: [PATCH 2/2] Fix for PEAR Bug #21243 Small blocks are not contiguous but a read from within big blocks. Fix in the nature of that outlined by the reporter. --- OLE.php | 10 ++++++++++ OLE/ChainedBlockStream.php | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/OLE.php b/OLE.php index e9631bf..9185ede 100755 --- a/OLE.php +++ b/OLE.php @@ -58,6 +58,12 @@ class OLE extends PEAR */ var $_file_handle; + /** + * Reference to the sbat stream + * @var resource + */ + var $_small_handle; + /** * Array of PPS's found on the OLE container * @var array @@ -340,6 +346,10 @@ function _readPpsWks($blockId) $pps->No = count($this->_list); $this->_list[] = $pps; + if ($type == OLE_PPS_TYPE_ROOT) { + $this->_small_handle = $this->getStream($pps->_StartBlock); + } + // check if the PPS tree (starting from root) is complete if (isset($this->root) && $this->_ppsTreeComplete($this->root->No)) { diff --git a/OLE/ChainedBlockStream.php b/OLE/ChainedBlockStream.php index d6e805b..49bfcbb 100644 --- a/OLE/ChainedBlockStream.php +++ b/OLE/ChainedBlockStream.php @@ -109,12 +109,13 @@ function stream_open($path, $mode, $options, &$openedPath) $blockId != $this->ole->root->_StartBlock) { // Block id refers to small blocks - $rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock); + $rootPos = 0; while ($blockId != -2) { - $pos = $rootPos + $blockId * $this->ole->bigBlockSize; - $blockId = $this->ole->sbat[$blockId]; - fseek($this->ole->_file_handle, $pos); - $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); + $pos = $rootPos + $blockId * $this->ole->smallBlockSize; + + $blockId = $this->ole->sbat[$blockId]; + fseek($this->ole->_small_handle, $pos); + $this->data .= fread($this->ole->_small_handle, $this->ole->smallBlockSize); } } else { // Block id refers to big blocks