007868a
From 4bef1a1d32e29b68855616020dbff574b9cda08f Mon Sep 17 00:00:00 2001
007868a
From: Robin Watts <Robin.Watts@artifex.com>
007868a
Date: Thu, 29 Dec 2016 15:57:43 +0000
007868a
Subject: [PATCH] Bug 697453: Avoid divide by 0 in scan conversion code.
007868a
007868a
Arithmetic overflow due to extreme values in the scan conversion
007868a
code can cause a division by 0.
007868a
007868a
Avoid this with a simple extra check.
007868a
007868a
  dx_old=cf814d81
007868a
  endp->x_next=b0e859b9
007868a
  alp->x_next=8069a73a
007868a
007868a
leads to dx_den = 0
007868a
---
007868a
 base/gxfill.c | 4 ++--
007868a
 1 file changed, 2 insertions(+), 2 deletions(-)
007868a
007868a
diff --git a/base/gxfill.c b/base/gxfill.c
007868a
index 99196c0..2f81bb0 100644
007868a
--- a/base/gxfill.c
007868a
+++ b/base/gxfill.c
007868a
@@ -1741,7 +1741,7 @@ intersect(active_line *endp, active_line *alp, fixed y, fixed y1, fixed *p_y_new
007868a
     fixed dx_old = alp->x_current - endp->x_current;
007868a
     fixed dx_den = dx_old + endp->x_next - alp->x_next;
007868a
 
007868a
-    if (dx_den <= dx_old)
007868a
+    if (dx_den <= dx_old || dx_den == 0)
007868a
         return false; /* Intersection isn't possible. */
007868a
     dy = y1 - y;
007868a
     if_debug3('F', "[F]cross: dy=%g, dx_old=%g, dx_new=%g\n",
007868a
@@ -1750,7 +1750,7 @@ intersect(active_line *endp, active_line *alp, fixed y, fixed y1, fixed *p_y_new
007868a
     /* Do the computation in single precision */
007868a
     /* if the values are small enough. */
007868a
     y_new =
007868a
-        ((dy | dx_old) < 1L << (size_of(fixed) * 4 - 1) ?
007868a
+        (((ufixed)(dy | dx_old)) < (1L << (size_of(fixed) * 4 - 1)) ?
007868a
          dy * dx_old / dx_den :
007868a
          (INCR_EXPR(mq_cross), fixed_mult_quo(dy, dx_old, dx_den)))
007868a
         + y;
007868a
-- 
007868a
2.9.3
007868a