smalot / smalot/pdfparser

ElementHexa "Invalid characters passed for attempted conversion, these have been ignored"

Open
#429 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix help wanted
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

Came across a PDF making the ElementHexa decode() throw exceptions at
hexdec($hex_string = '00\n0') ..../pdfparser/src/Smalot/PdfParser/Element/ElementHexa.php:78

For some strange reason when decoding the parseHeaderElement the value passed has '\n' characters.
The solution I've applied is to add at line 73 of ElementHexa.php
$value = preg_replace('/\n/i', '', $value);

Hope this helps.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pdfparser/src/Smalot/PdfParser/Element/ElementHexa.php around line 78, where hexdec() receives the value from parseHeaderElement. Reproduce the reported PDF case with a value containing a newline, then verify that ElementHexa::decode() completes without throwing and preserves the expected decoded result.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.