Fix chr() deprecation in ASCII85 last-tuple decoding#793
Open
Ciki wants to merge 1 commit intosmalot:masterfrom
Open
Fix chr() deprecation in ASCII85 last-tuple decoding#793Ciki wants to merge 1 commit intosmalot:masterfrom
Ciki wants to merge 1 commit intosmalot:masterfrom
Conversation
PR smalot#779 fixed the chr() deprecation warning in the main decoding loop but missed the "last tuple" switch/case block (lines 233-248) which handles incomplete groups at the end of the encoded data. The same issue applies: bit-shifted values ($tuple >> 16, $tuple >> 8) can exceed 255, triggering: chr(): Providing a value not in-between 0 and 255 is deprecated Apply `& 0xFF` bitmask to extract individual bytes, consistent with the fix in the main loop.
Collaborator
|
@Ciki Thank you for the PR. If I remember correctly, the changes in #779 where suggested somewhere to fix PHP 8.5 related deprecations. I have limited knowledge in this area so I had to check your information. The following two pages describe bit-wise operations quite a bit:
Code looks good. Could you provide one of the PDFs which triggered these so we can use it in our test suite? I will keep this open for a few days in case someone else wants to comment. Or do you need it merged right away? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #779 fixed the
chr()deprecation warning in the main ASCII85 decoding loop but missed the "last tuple" switch/case block (handling incomplete groups at the end of encoded data).The same issue applies — bit-shifted values (
$tuple >> 16,$tuple >> 8) can exceed 255, triggering:Observed in production when parsing PDFs with ASCII85-encoded streams that have a partial trailing group.
Fix
Apply
& 0xFFbitmask to extract individual bytes before passing tochr(), consistent with the approach used in the main loop fix from #779.& 0xFFis the standard bitwise idiom for extracting a single byte from a multi-byte integer (equivalent to% 256but more idiomatic).Changes
Same pattern applied to
case 3andcase 2.