[BUGFIX] Prevent division by zero when scaling image 99/60299/3
authorClaus Due <claus@namelesscoder.net>
Tue, 19 Mar 2019 14:35:28 +0000 (15:35 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 5 Jun 2019 20:11:29 +0000 (22:11 +0200)
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>
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Tests/Unit/Imaging/GraphicalFunctionsTest.php

index 742f29c..3fb8e23 100644 (file)
@@ -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;
index 0b79909..58eabe4 100644 (file)
@@ -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
+                ],
+            ],
         ];
     }