Skip to content

Commit

Permalink
[BUGFIX] Prevent division by zero when scaling image
Browse files Browse the repository at this point in the history
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 <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
NamelessCoder authored and maddy2101 committed Jun 5, 2019
1 parent c39bf90 commit a3b2904
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
Expand Up @@ -2343,8 +2343,8 @@ public function getImageScale($info, $w, $h, $options)
$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;
Expand Down
14 changes: 14 additions & 0 deletions typo3/sysext/core/Tests/Unit/Imaging/GraphicalFunctionsTest.php
Expand Up @@ -84,6 +84,20 @@ public function getScaleForImageDataProvider()
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
],
],
];
}

Expand Down

0 comments on commit a3b2904

Please sign in to comment.