pdfparser icon indicating copy to clipboard operation
pdfparser copied to clipboard

Exception not handling on "Allowed memory size exhausted"

Open bastienuh opened this issue 2 years ago • 7 comments

Hi,

I have the following exception :

Symfony\Component\ErrorHandler\Error\FatalError

  Allowed memory size of 536870912 bytes exhausted (tried to allocate 167772160 bytes)

  at vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php:221
    217▕                         $char_to = hexdec($matches['to'][$key]);
    218▕                         $offset = hexdec($matches['offset'][$key]);
    219▕
    220▕                         for ($char = $char_from; $char <= $char_to; ++$char) {
  ➜ 221▕                             $this->table[$char] = self::uchr($char - $char_from + $offset);
    222▕                         }
    223▕                     }
    224▕
    225▕                     // Support for : <srcCode1> <srcCodeN> [<dstString1> <dstString2> ... <dstStringN>]

I tried to handle it by a try / catch, but it's not working:

try {
    echo 'A';
    $pdf = $pdfParser->parseFile($pathname.'.pdf');
}
catch (\Whoops\Exception\ErrorException $e) {
    echo ' - Error in $pdf->parseFile() : '.$e->getMessage().' - ';
    return $new_document;
}
catch (\Symfony\Component\ErrorHandler\Error\FatalError $e) {
    echo ' - Error in $pdf->parseFile() : '.$e->getMessage().' - ';
    return $new_document;
}
catch (\Exception $e) {
    echo ' - Error in $pdf->parseFile() : '.$e->getMessage().' - ';
    return $new_document;
}
echo 'B';

The error is in parseFile() because the "A" is echoing, but not the "B".

Do you know why the exception is not handling? Maybe it can be a solution to add a try / catch around the self::uchr ?

Thanks for your help and advice :-)

(If it could help, the parsed PDF is here : https://www.assemblee-nationale.fr/dyn/opendata/PIONANR5L15TAP0528.pdf)

bastienuh avatar Mar 08 '22 17:03 bastienuh