From 8ec72a7f19f8f15f8565c89ef96aa08da7cfaff7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 4 May 2013 16:38:09 +0000 Subject: [PATCH] Missed to initialize arrays before pushing new entries on them. This might be a candidate for a rewrite to a 'generic array entry handling' or so --- .../fragmenter/class_PackageFragmenter.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/application/hub/main/package/fragmenter/class_PackageFragmenter.php b/application/hub/main/package/fragmenter/class_PackageFragmenter.php index 277083d6e..7214942cf 100644 --- a/application/hub/main/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/main/package/fragmenter/class_PackageFragmenter.php @@ -279,7 +279,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera * Get the crypto instance and hash the data with no extra salt because * the other peer doesn't have *this* peer's salt. */ - $hash = $this->getCryptoInstance()->hashString($rawData, '', false); + $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE); // Return it return $hash; @@ -354,9 +354,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera * @param $prepend Whether append (default) or prepend the chunk * @return void */ - private function addChunkData ($finalHash, $chunkData, $prepend = false) { + private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) { // Hash it - $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', false); + $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE); // Prepend the hash to the chunk $rawData = ( @@ -370,7 +370,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackage::TCP_PACKAGE_SIZE); // Add it to the array - if ($prepend === true) { + if ($prepend === TRUE) { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...'); array_unshift($this->chunkHashes[$finalHash], $rawDataHash); @@ -378,7 +378,16 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera } else { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ': Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...'); - $this->chunks[$finalHash][] = $rawData; + + // Is the array there? + if (!isset($this->chunks[$finalHash])) { + // Then initialize it + $this->chunks[$finalHash] = array(); + $this->chunkHashes[$finalHash] = array(); + } // END - if + + // Add both + array_push($this->chunks[$finalHash] , $rawData); array_push($this->chunkHashes[$finalHash], $rawDataHash); } } -- 2.39.5