PDF memory optimizations (#2736)

This commit is contained in:
Kevin Papst
2021-11-14 02:51:52 +01:00
committed by GitHub
parent 6e6c60b29a
commit a483184372
5 changed files with 21 additions and 4 deletions

View File

@@ -12,12 +12,13 @@ As announced in the [README](README.md) I only support the latest available rele
## Reporting a Vulnerability
Please report any security related vulnerability in the [advisories section at GitHub](https://github.com/kevinpapst/kimai2/security/advisories) or via email to info@keleo.de or kpapst@gmx.net.
Please read the [Bughunter](https://www.kimai.org/documentation/bughunter.html) documentation before posting,
and then you can report any security related vulnerability in the [advisories section at GitHub](https://github.com/kevinpapst/kimai2/security/advisories) or via email to kpapst@gmx.net.
I will work as fast as I can to fix the problem and publish a bugfix release / security update.
Depending on the size of the required fixes, this might take a couple of hours or a couple of days.
You can expect that your message will be answered ASAP, but please take into account that I am living in the timezone CET.
You can expect that your message will be answered ASAP.
If your issue is valid and after I verified and fixed it, you will be mentioned in the release notes.
I am grateful for any (discrete) disclosure of vulnerabilities!
I am grateful for any (discrete) disclosure of vulnerabilities!

View File

@@ -74,11 +74,23 @@ class MPdfConverter implements HtmlToPdfConverter
@ini_set('pcre.backtrack_limit', '1000000');
}
// large amount of data take time
@ini_set('max_execution_time', '120');
// reduce the size of content parts that are passed to MPDF, to prevent
// https://mpdf.github.io/troubleshooting/known-issues.html#blank-pages-or-some-sections-missing
$parts = explode('<pagebreak>', $html);
for ($i = 0; $i < \count($parts); $i++) {
$mpdf->WriteHTML($parts[$i]);
if (stripos($parts[$i], '<!-- CONTENT_PART -->') !== false) {
$subParts = explode('<!-- CONTENT_PART -->', $parts[$i]);
$run = 0;
foreach ($subParts as $subPart) {
$mpdf->WriteHTML($subPart);
}
} else {
$mpdf->WriteHTML($parts[$i]);
}
if ($i < \count($parts) - 1) {
$mpdf->WriteHTML('<pagebreak>');
}

View File

@@ -140,6 +140,7 @@ mpdf-->
{% set totalInternalRate = 0 %}
{% set totalRate = 0 %}
{% for id, summary in summaries %}
<!-- CONTENT_PART -->
{% set totalDuration = totalDuration + summary.duration %}
{% set totalInternalRate = totalInternalRate + summary.rate_internal %}
{% set totalRate = totalRate + summary.rate %}
@@ -274,6 +275,7 @@ mpdf-->
</thead>
<tbody>
{% for entry in entries %}
<!-- CONTENT_PART -->
{% set duration = duration + entry.duration %}
{% if currency is same as(false) %}
{% set currency = entry.project.customer.currency %}

View File

@@ -102,6 +102,7 @@ mpdf-->
</thead>
<tbody>
{% for id, entry in model.calculator.entries %}
<!-- CONTENT_PART -->
{% set duration = entry.duration|duration(isDecimal) %}
{% if entry.fixedRate %}
{% set rate = entry.fixedRate %}

View File

@@ -109,6 +109,7 @@ mpdf-->
</thead>
<tbody>
{% for entry in model.calculator.entries %}
<!-- CONTENT_PART -->
{% set duration = entry.duration|duration(isDecimal) %}
{% if entry.fixedRate is not null %}
{% set rate = entry.fixedRate %}