Skip to content

Commit

Permalink
Fix ASCII85 decoding in a specific case
Browse files Browse the repository at this point in the history
When the start or the end of the string is "<~>". In this case
we must be sure of the exact position of this substring: e.g.
when there is no "<~" header but "<~>" at the end, we must not
remove the first two characters even if "<~" is found somewhere.

Issue: #599
  • Loading branch information
Seb35 committed May 2, 2023
1 parent 9094d77 commit 94977a2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Smalot/PdfParser/RawData/FilterHelper.php
Expand Up @@ -150,13 +150,13 @@ protected function decodeFilterASCII85Decode(string $data): string
// all white-space characters shall be ignored
$data = preg_replace('/[\s]/', '', $data);
// remove start sequence 2-character sequence <~ (3Ch)(7Eh)
if (false !== strpos($data, '<~')) {
if (0 === strpos($data, '<~')) {
// remove EOD and extra data (if any)
$data = substr($data, 2);
}
// check for EOD: 2-character sequence ~> (7Eh)(3Eh)
$eod = strpos($data, '~>');
if (false !== $eod) {
if (\strlen($data) - 2 === $eod) {
// remove EOD and extra data (if any)
$data = substr($data, 0, $eod);
}
Expand Down

0 comments on commit 94977a2

Please sign in to comment.