snappy icon indicating copy to clipboard operation
snappy copied to clipboard

Uncaught crash with html header or footer caused by wrong length estimation

Open Adelysnet opened this issue 2 years ago • 6 comments

Hi,

i don't know the exact reason, but some times, html headers|footers (strings) sent in option don't pass the isFile test, crashing with a 500 error code. i suppose, depending of the encoding (utf8 in my case), the value length is miscalculated and this test fails in the AbstractGenerator (line 695) : protected function isFile($filename) { return \strlen($filename) <= \PHP_MAXPATHLEN && \is_file($filename); }

causing the is_file function to crash. I tried to replace strlen by mb_strlen without success but add an error control operator @\is_file does the trick :

protected function isFile($filename) { return \strlen($filename)

Adelysnet avatar Feb 03 '23 17:02 Adelysnet

Hello @Adelysnet!

Could you provide a reproducible gist or any equivalent ? It is hard tell what could be wrong with the information you currently provided.

Did you manage to spot anything that could help ?

AntoineLelaisant avatar Mar 17 '23 15:03 AntoineLelaisant

Hi Antoine,

here is the Gist : https://gist.github.com/Adelysnet/8c52f20f06b82192aec4ecfb8e6cfd7f

Just call the generatePDF method like so : $html = '<html><head><title>Test</title></head><body><h1>Test</h1></body></html>';
$pdfManager->generatePDF( $html );

Env : PHP Version 8.1.16 Symfony : 5.4

Romain

Adelysnet avatar Mar 20 '23 14:03 Adelysnet

Hi @Adelysnet ,

You wrote that "some times" the generation fails. Do you know every how many generation it fails? I cannot reproduce what you are experiencing with a "filename" with a length longer than PHP_MAXPATHLEN

Do you have the message that triggered the 500 error code?

qroques avatar Apr 05 '23 15:04 qroques

Hello @Adelysnet, We can't replicate the issue you are having using your gist. Are you sure your issue is related to the isFile function? In your example you don't generate a filename that's slightly below the PHP_MAXPATHLEN but an header that's slightly below that length. Are you sure that you don't have any issue reading/writing that file instead and, therefore, it's correct that theisFile function returns false?

alexpozzi avatar May 12 '23 13:05 alexpozzi

Hi @alexpozzi the header-html option pass the optionsWithContentCheck test in the Pdf class, so the value (can be html string or filename) is sent to the isFile function, which in my environnement crash.

Adelysnet avatar May 12 '23 14:05 Adelysnet

Oh! You are right, my bad, I missed that. Can you give us more info on your environment? Like OS, Docker version (if using Docker) etc...? I think that the assertion should be adjusted in order to better support this case.

alexpozzi avatar May 12 '23 15:05 alexpozzi