I attached a patch made by Peter Selinger.

-- 
Henri Salo
diff -u -Naur potrace-1.14-orig/src/bitmap_io.c potrace-1.14/src/bitmap_io.c
--- potrace-1.14-orig/src/bitmap_io.c	2017-02-19 00:39:08.000000000 -0400
+++ potrace-1.14/src/bitmap_io.c	2017-08-02 14:59:50.703002306 -0300
@@ -689,11 +689,11 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
-	  BM_UPUT(bm, x, y, col[i&1]);
+	  BM_PUT(bm, x, y, col[i&1]);
 	  x++;
 	}
       } else if (c == 0) {
@@ -719,7 +719,7 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
@@ -747,11 +747,11 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
-	  BM_UPUT(bm, x, y, COLTABLE(c));
+	  BM_PUT(bm, x, y, COLTABLE(c));
 	  x++;
 	}
       } else if (c == 0) {
@@ -775,7 +775,7 @@
             x=0;
             y++;
           }
-          if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
             break;
           }
           realheight = y+1;
diff -u -Naur potrace-1.14-orig/src/decompose.c potrace-1.14/src/decompose.c
--- potrace-1.14-orig/src/decompose.c	2017-02-19 00:39:08.000000000 -0400
+++ potrace-1.14/src/decompose.c	2017-08-02 14:59:50.703002306 -0300
@@ -199,7 +199,8 @@
    cannot have length 0). Sign is required for correct interpretation
    of turnpolicies. */
 static path_t *findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turnpolicy) {
-  int x, y, dirx, diry, len, size, area;
+  int x, y, dirx, diry, len, size;
+  unsigned long long int area;
   int c, d, tmp;
   point_t *pt, *pt1;
   path_t *p = NULL;
@@ -276,7 +277,7 @@
 
   p->priv->pt = pt;
   p->priv->len = len;
-  p->area = area;
+  p->area = area <= 0x7fffffff ? area : 0x7fffffff; /* avoid overflow */
   p->sign = sign;
 
   return p;
diff -u -Naur potrace-1.14-orig/src/greymap.c potrace-1.14/src/greymap.c
--- potrace-1.14-orig/src/greymap.c	2017-02-19 01:10:51.000000000 -0400
+++ potrace-1.14/src/greymap.c	2017-08-02 14:59:50.704002324 -0300
@@ -845,11 +845,11 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
-	  GM_UPUT(gm, x, y, col[i&1]);
+	  GM_PUT(gm, x, y, col[i&1]);
 	  x++;
 	}
       } else if (c == 0) {
@@ -875,7 +875,7 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
@@ -903,11 +903,11 @@
 	    x=0;
 	    y++;
 	  }
-	  if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
 	    break;
 	  }
           realheight = y+1;
-	  GM_UPUT(gm, x, y, COLTABLE(c));
+	  GM_PUT(gm, x, y, COLTABLE(c));
 	  x++;
 	}
       } else if (c == 0) {
@@ -931,7 +931,7 @@
             x=0;
             y++;
           }
-          if (y>=bmpinfo.h) {
+	  if (x>=bmpinfo.w || y>=bmpinfo.h) {
             break;
           }
           realheight = y+1;
diff -u -Naur potrace-1.14-orig/src/greymap.h potrace-1.14/src/greymap.h
--- potrace-1.14-orig/src/greymap.h	2017-02-19 00:39:08.000000000 -0400
+++ potrace-1.14/src/greymap.h	2017-08-02 14:59:50.704002324 -0300
@@ -41,7 +41,7 @@
 #define GM_INC(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UINC(gm, x, y, b) : 0)
 #define GM_INV(gm, x, y) (gm_safe(gm, x, y) ? GM_UINV(gm, x, y) : 0)
 #define GM_PUT(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UPUT(gm, x, y, b) : 0)
-#define GM_BGET(gm, x, y) GM_UGET(gm, gm_bound(x, gm->w), gm_bound(y, gm->h))
+#define GM_BGET(gm, x, y) ((gm)->w == 0 || (gm)->h == 0 ? 0 : GM_UGET(gm, gm_bound(x, (gm)->w), gm_bound(y, (gm)->h)))
 
 /* modes for cutting off out-of-range values. The following names
    refer to winding numbers. I.e., make a pixel black if winding
diff -u -Naur potrace-1.14-orig/src/mkbitmap.c potrace-1.14/src/mkbitmap.c
--- potrace-1.14-orig/src/mkbitmap.c	2017-02-19 00:39:08.000000000 -0400
+++ potrace-1.14/src/mkbitmap.c	2017-08-02 14:59:50.704002324 -0300
@@ -332,9 +332,9 @@
 	    v += window[k][i] * poly[l][i];
 	  }
 	  if (bilevel) {
-	    BM_UPUT(bm_out, x*s+l, y*s+k, v < c1);
+	    BM_PUT(bm_out, x*s+l, y*s+k, v < c1);
 	  } else {
-	    GM_UPUT(gm_out, x*s+l, y*s+k, v);
+	    GM_PUT(gm_out, x*s+l, y*s+k, v);
 	  }	    
 	}
       }

Attachment: signature.asc
Description: PGP signature



Reply via email to