Allowed memory size exhausted on Font.php line 150
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version:
PHP 8.3.10 (cli) - PDFParser Version:
smalot/pdfparser": "^2.11"
Description:
PDF input
Expected output & actual output
Getting error:
PHP Fatal error: Allowed memory size of 3221225472 bytes exhausted (tried to allocate 1342177280 bytes) in ../smalot/pdfparser/src/Smalot/PdfParser/Font.php on line 150
Symfony\Component\ErrorHandler\Error\FatalError
`Allowed memory size of 3221225472 bytes exhausted (tried to allocate 1342177280 bytes)
at vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php:150
146▕
147▕ if (!isset(self::$uchrCache[$code])) {
148▕ // html_entity_decode() will not work with UTF-16 or UTF-32 char entities,
149▕ // therefore, we use mb_convert_encoding() instead
➜ 150▕ self::$uchrCache[$code] = mb_convert_encoding("&#{$code};", 'UTF-8', 'HTML-ENTITIES');
151▕ }
152▕
153▕ return self::$uchrCache[$code];
154▕ }
`Whoops\Exception\ErrorException
Allowed memory size of 3221225472 bytes exhausted (tried to allocate 1342177280 bytes)
at vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php:150
146▕
147▕ if (!isset(self::$uchrCache[$code])) {
148▕ // html_entity_decode() will not work with UTF-16 or UTF-32 char entities,
149▕ // therefore, we use mb_convert_encoding() instead
➜ 150▕ self::$uchrCache[$code] = mb_convert_encoding("&#{$code};", 'UTF-8', 'HTML-ENTITIES');
151▕ }
152▕
153▕ return self::$uchrCache[$code];
154▕ }
+1 vendor frames
2 [internal]:0
Whoops\Run::handleShutdown()
Code
$this->pdfParser = new Parser();
$pdf = $this->pdfParser->parseFile($file);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the attached unparseble.pdf through Parser->parseFile(), then inspect the character conversion and cache handling at src/Smalot/PdfParser/Font.php:150. Done means the provided PDF can be parsed without exhausting the configured memory limit, with the relevant behavior covered by an appropriate test if the project has one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100