From 7798dfbfa76e420d9c696c2cb5be60cfd66b23d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 6 Jan 2021 20:59:09 +0100 Subject: [PATCH] Continued: - fixed bug which occured because the last block was counted twice. This happened when read() returns an empty (zero length) string which was not properly handled (maybe EOF reached). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../binary/class_BaseBinaryFile.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php index 6a0cd6ca..ac37fd24 100644 --- a/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php +++ b/framework/main/classes/file_directories/binary/class_BaseBinaryFile.php @@ -317,7 +317,7 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { $endPosition = $idx * $minimumBlockLength + $minimumBlockLength; // Mark start and end position as gap - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->addGap(%d, %d) ...', $startPosition, $endPosition)); $this->addGap($startPosition, $endPosition); } @@ -791,18 +791,18 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { // Output message (as this may take some time) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Analyzing file structure ... (this may take some time)')); - // First rewind to the begining - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->rewind() ...'); - $this->rewind(); + // First Seek to right after file header + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: Calling this->seek(%d) ...', $this->getHeaderSize() + 1)); + $this->seek($this->getHeaderSize() + 1); // Then try to load all entries - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Looping through file'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, looping through file ...', $this->getSeekPosition())); while ($this->isValid()) { // Get current entry $current = $this->getCurrentBlock(); // Go to next entry - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-BINARY-FILE: Calling this->readNextBlock() ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: current=%s, calling this->readNextBlock() ...', $current)); $this->readNextBlock(); /* @@ -881,7 +881,11 @@ abstract class BaseBinaryFile extends BaseAbstractFile implements BinaryFile { // Is the block empty? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: block()=%d,length=%d', strlen($block), $length)); - if (empty(trim($block, chr(0)))) { + if (strlen($block) == 0) { + // Read empty block, maybe EOF + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, block is empty, maybe EOF reached - BREAK!', $this->getSeekPosition())); + break; + } elseif (empty(trim($block, chr(0)))) { // Mark it as empty //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-BINARY-FILE: this->seekPosition=%d, calling this->markCurrentBlockAsEmpty(%d) ...', $this->getSeekPosition(), $length)); $this->markCurrentBlockAsEmpty($length); -- 2.39.2