From bb064a610de0e90ad40f5c74463f2b18a30b02fb Mon Sep 17 00:00:00 2001 From: nnoujaim Date: Fri, 5 Oct 2018 12:29:49 -0400 Subject: [PATCH] Update PerspectiveTransform.php On some error correction levels the $denominator variable on line 114 will end up being the integer 0. This is then used as the denominator in the next 2 lines in division which will cause PHP to fatal error and crash the program. By throwing an exception instead we can catch the error and handle it properly. --- lib/Common/PerspectiveTransform.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Common/PerspectiveTransform.php b/lib/Common/PerspectiveTransform.php index a3a0b97..5030d66 100644 --- a/lib/Common/PerspectiveTransform.php +++ b/lib/Common/PerspectiveTransform.php @@ -112,6 +112,9 @@ public static function squareToQuadrilateral( $dy1 = $y1 - $y2; $dy2 = $y3 - $y2; $denominator = $dx1 * $dy2 - $dx2 * $dy1; + if ((int)$denominator === 0) { + throw new \Exception('Cannot divide by 0, reduce error correction level and try again'); + } $a13 = ($dx3 * $dy2 - $dx2 * $dy3) / $denominator; $a23 = ($dx1 * $dy3 - $dx3 * $dy1) / $denominator;