Skip to content

Commit

Permalink
Prevent zero from being passed to array_chunk() (#686)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GreyWyvern authored Mar 12, 2024
1 parent 6b53144 commit 6c9617c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Smalot/PdfParser/RawData/RawDataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 6c9617c

Please sign in to comment.