Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Adelysnet opened this issue Feb 3, 2023 · 6 comments
Assignees

Comments

@Adelysnet
Copy link

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) <= \PHP_MAXPATHLEN && @\is_file($filename); }
@Adelysnet Adelysnet changed the title Uncauht crash with html header or footer caused by wrong length estimation Uncaught crash with html header or footer caused by wrong length estimation Feb 4, 2023
@AntoineLelaisant
Copy link

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 ?

@Adelysnet
Copy link
Author

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

@qroques
Copy link
Collaborator

qroques commented Apr 5, 2023

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?

@alexpozzi
Copy link
Member

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?

@Adelysnet
Copy link
Author

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.

@alexpozzi
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants