From 0c18bca69fad1e1332082dd1612e72995a54e02f Mon Sep 17 00:00:00 2001 From: Sebijk Date: Tue, 6 Jun 2023 20:39:15 +0200 Subject: [PATCH] update FPDI to 2.3.7 --- src/serverlib/3rdparty/fpdf/fpdi/src/Fpdi.php | 2 +- .../PdfParser/CrossReference/FixedReader.php | 1 + .../PdfParser/CrossReference/LineReader.php | 1 + .../fpdf/fpdi/src/PdfParser/Filter/Lzw.php | 35 +++++++------------ .../fpdi/src/PdfParser/Type/PdfStream.php | 11 ++---- .../fpdf/fpdi/src/PdfReader/PdfReader.php | 8 ++++- .../3rdparty/fpdf/fpdi/src/Tcpdf/Fpdi.php | 3 +- .../3rdparty/fpdf/fpdi/src/Tfpdf/Fpdi.php | 2 +- 8 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/Fpdi.php b/src/serverlib/3rdparty/fpdf/fpdi/src/Fpdi.php index 157f87c..dc46bb1 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/Fpdi.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/Fpdi.php @@ -29,7 +29,7 @@ class Fpdi extends FpdfTpl * * @string */ - const VERSION = '2.3.6'; + const VERSION = '2.3.7'; protected function _enddoc() { diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/FixedReader.php b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/FixedReader.php index 883feec..ed417df 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/FixedReader.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/FixedReader.php @@ -58,6 +58,7 @@ class FixedReader extends AbstractReader implements ReaderInterface /** * @inheritdoc + * @return int|false */ public function getOffsetFor($objectNumber) { diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/LineReader.php b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/LineReader.php index b6f0e42..5b67744 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/LineReader.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/CrossReference/LineReader.php @@ -42,6 +42,7 @@ class LineReader extends AbstractReader implements ReaderInterface /** * @inheritdoc + * @return int|false */ public function getOffsetFor($objectNumber) { diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Filter/Lzw.php b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Filter/Lzw.php index bedb5b7..0d6cf38 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Filter/Lzw.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Filter/Lzw.php @@ -87,37 +87,28 @@ class Lzw implements FilterInterface $this->nextData = 0; $this->nextBits = 0; - $oldCode = 0; + $prevCode = 0; $uncompData = ''; while (($code = $this->getNextCode()) !== 257) { if ($code === 256) { $this->initsTable(); - $code = $this->getNextCode(); - - if ($code === 257) { - break; - } - + } elseif ($prevCode === 256) { $uncompData .= $this->sTable[$code]; - $oldCode = $code; + } elseif ($code < $this->tIdx) { + $string = $this->sTable[$code]; + $uncompData .= $string; + + $this->addStringToTable($this->sTable[$prevCode], $string[0]); } else { - if ($code < $this->tIdx) { - $string = $this->sTable[$code]; - $uncompData .= $string; + $string = $this->sTable[$prevCode]; + $string .= $string[0]; + $uncompData .= $string; - $this->addStringToTable($this->sTable[$oldCode], $string[0]); - $oldCode = $code; - } else { - $string = $this->sTable[$oldCode]; - $string .= $string[0]; - $uncompData .= $string; - - $this->addStringToTable($string); - $oldCode = $code; - } + $this->addStringToTable($string); } + $prevCode = $code; } return $uncompData; @@ -163,7 +154,7 @@ class Lzw implements FilterInterface /** * Returns the next 9, 10, 11 or 12 bits. * - * @return integer + * @return int */ protected function getNextCode() { diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Type/PdfStream.php b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Type/PdfStream.php index 6d4c5a8..7adf218 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Type/PdfStream.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfParser/Type/PdfStream.php @@ -46,9 +46,8 @@ class PdfStream extends PdfType // Find the first "newline" while (($firstByte = $reader->getByte($offset)) !== false) { - if ($firstByte !== "\n" && $firstByte !== "\r") { - $offset++; - } else { + $offset++; + if ($firstByte === "\n" || $firstByte === "\r") { break; } } @@ -60,11 +59,7 @@ class PdfStream extends PdfType ); } - $sndByte = $reader->getByte($offset + 1); - if ($firstByte === "\n" || $firstByte === "\r") { - $offset++; - } - + $sndByte = $reader->getByte($offset); if ($sndByte === "\n" && $firstByte !== "\n") { $offset++; } diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfReader/PdfReader.php b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfReader/PdfReader.php index 3ee8878..e31b110 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/PdfReader/PdfReader.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/PdfReader/PdfReader.php @@ -202,7 +202,8 @@ class PdfReader return; } - $readPages = function ($kids, $count) use (&$readPages, $readAll) { + $expectedPageCount = $this->getPageCount(); + $readPages = function ($kids, $count) use (&$readPages, $readAll, $expectedPageCount) { $kids = PdfArray::ensure($kids); $isLeaf = ($count->value === \count($kids->value)); @@ -222,6 +223,11 @@ class PdfReader } else { $this->pages[] = $object; } + + // stop if all pages are read - faulty documents exists with additional entries with invalid data. + if (count($this->pages) === $expectedPageCount) { + break; + } } }; diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/Tcpdf/Fpdi.php b/src/serverlib/3rdparty/fpdf/fpdi/src/Tcpdf/Fpdi.php index 159f97b..90c11b8 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/Tcpdf/Fpdi.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/Tcpdf/Fpdi.php @@ -42,7 +42,7 @@ class Fpdi extends \TCPDF * * @string */ - const VERSION = '2.3.6'; + const VERSION = '2.3.7'; /** * A counter for template ids. @@ -140,6 +140,7 @@ class Fpdi extends \TCPDF /** * @inheritdoc + * @return string */ protected function _getxobjectdict() { diff --git a/src/serverlib/3rdparty/fpdf/fpdi/src/Tfpdf/Fpdi.php b/src/serverlib/3rdparty/fpdf/fpdi/src/Tfpdf/Fpdi.php index 77f340f..9af3f88 100755 --- a/src/serverlib/3rdparty/fpdf/fpdi/src/Tfpdf/Fpdi.php +++ b/src/serverlib/3rdparty/fpdf/fpdi/src/Tfpdf/Fpdi.php @@ -30,7 +30,7 @@ class Fpdi extends FpdfTpl * * @string */ - const VERSION = '2.3.6'; + const VERSION = '2.3.7'; public function _enddoc() {