Commit a3b2904c authored by Claus Due's avatar Claus Due Committed by Anja Leichsenring
Browse files

[BUGFIX] Prevent division by zero when scaling image

Prevents multiple division by zero errors when scaling
images, by checking that the input image size is valid
(meaning non-zero) before attempting to calculate
the ratio for scaling - because the ratio is based on the
input size parameters that must not be zero.

Change-Id: I33fd3e49a1b3dcdc319309af736a9d785130af94
Releases: master, 9.5, 8.7
Resolves: #87954
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60299

Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent c39bf90e
......@@ -2343,8 +2343,8 @@ class GraphicalFunctions
$h = $info[1];
}
}
// If scaling should be performed
if ($w || $h) {
// If scaling should be performed. Check that input "info" array will not cause division-by-zero
if (($w || $h) && $info[0] && $info[1]) {
if ($w && !$h) {
$info[1] = ceil($info[1] * ($w / $info[0]));
$info[0] = $w;
......
......@@ -84,6 +84,20 @@ class GraphicalFunctionsTest extends UnitTestCase
1 => (float)136
],
],
'No PHP warning for zero in input dimensions when scaling' => [
[0, 0],
'50',
'',
[],
[
'crs' => false,
'origW' => 50,
'origH' => 0,
'max' => 0,
0 => 0,
1 => 0
],
],
];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment