From 78703789e323007c751ad69111582422abffe5d0 Mon Sep 17 00:00:00 2001 From: Brian Huisman Date: Wed, 6 Mar 2024 10:11:27 -0500 Subject: [PATCH] Prevent zero from being passed to array_chunk() Passing a zero (0) value to the `array_chunk()` function causes an error, and in rare cases, a PDF XRef object may be added to a document with an "empty" `/W [0 0 0]` command. This would cause the `$rowlen` variable to be set to zero and cause an error. Add a simple check to return an empty array in this case. --- src/Smalot/PdfParser/RawData/RawDataParser.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Smalot/PdfParser/RawData/RawDataParser.php b/src/Smalot/PdfParser/RawData/RawDataParser.php index 6b04fae5..7b43305f 100644 --- a/src/Smalot/PdfParser/RawData/RawDataParser.php +++ b/src/Smalot/PdfParser/RawData/RawDataParser.php @@ -408,10 +408,15 @@ protected function decodeXrefStream(string $pdfData, int $startxref, array $xref } else { // number of bytes in a row $rowlen = array_sum($wb); - // convert the stream into an array of integers - $sdata = unpack('C*', $xrefcrs[1][3][0]); - // split the rows - $ddata = array_chunk($sdata, $rowlen); + if (0 < $rowlen) { + // convert the stream into an array of integers + $sdata = unpack('C*', $xrefcrs[1][3][0]); + // split the rows + $ddata = array_chunk($sdata, $rowlen); + } else { + // if the row length is zero, $ddata should be an empty array as well + $ddata = []; + } } $sdata = [];