Skip to content

Commit ddce0c1

Browse files
committed
Fixed the fix (chr)
1 parent 41c8080 commit ddce0c1

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Smalot/PdfParser/RawData/FilterHelper.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,34 @@ protected function decodeFilterASCII85Decode(string $data): string
190190
// the value represented by a group of 5 characters should never be greater than 2^32 - 1
191191
$tuple += (($char - 33) * $pow85[$group_pos]);
192192
if (4 == $group_pos) {
193-
// The following if-clause is an attempt to fix/suppress the following deprecation warning:
193+
// The following if-clauses are an attempt to fix/suppress the following deprecation warning:
194194
// chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value
195195
// must be in the [0, 255] interval. The value used will be constrained using % 256
196-
if (
197-
255 < $tuple >> 24
198-
|| 255 < $tuple >> 16
199-
|| 255 < $tuple >> 8
200-
) {
201-
$tuple = $tuple % 256;
196+
// I know this is ugly and there might be more fancier ways. If you know one, feel free to provide a pull request.
197+
if (255 < $tuple >> 8) {
198+
\chr($tuple >> 8);
199+
$chr8Part = \chr(($tuple >> 8) % 256);
200+
} else {
201+
$chr8Part = \chr($tuple >> 8);
202202
}
203203

204-
$decoded .= \chr($tuple >> 24)
205-
.\chr($tuple >> 16)
206-
.\chr($tuple >> 8)
204+
if (255 < $tuple >> 16) {
205+
\chr($tuple >> 16);
206+
$chr16Part = \chr(($tuple >> 16) % 256);
207+
} else {
208+
$chr16Part = \chr($tuple >> 16);
209+
}
210+
211+
if (255 < $tuple >> 24) {
212+
\chr($tuple >> 24);
213+
$chr24Part = \chr(($tuple >> 24) % 256);
214+
} else {
215+
$chr24Part = \chr($tuple >> 24);
216+
}
217+
218+
$decoded .= $chr24Part
219+
. $chr16Part
220+
. $chr8Part
207221
.\chr($tuple);
208222
$tuple = 0;
209223
$group_pos = 0;

0 commit comments

Comments
 (0)