@@ -2688,18 +2688,20 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2688
2688
return ;
2689
2689
}
2690
2690
2691
- if (overflow2 (sizeof (int ), n )) {
2692
- return ;
2693
- }
2694
-
2695
2691
if (c == gdAntiAliased ) {
2696
2692
fill_color = im -> AA_color ;
2697
2693
} else {
2698
2694
fill_color = c ;
2699
2695
}
2700
2696
2701
2697
if (!im -> polyAllocated ) {
2698
+ if (overflow2 (sizeof (int ), n )) {
2699
+ return ;
2700
+ }
2702
2701
im -> polyInts = (int * ) gdMalloc (sizeof (int ) * n );
2702
+ if (!im -> polyInts ) {
2703
+ return ;
2704
+ }
2703
2705
im -> polyAllocated = n ;
2704
2706
}
2705
2707
if (im -> polyAllocated < n ) {
@@ -2710,6 +2712,9 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2710
2712
return ;
2711
2713
}
2712
2714
im -> polyInts = (int * ) gdRealloc (im -> polyInts , sizeof (int ) * im -> polyAllocated );
2715
+ if (!im -> polyInts ) {
2716
+ return ;
2717
+ }
2713
2718
}
2714
2719
miny = p [0 ].y ;
2715
2720
maxy = p [0 ].y ;
@@ -2736,11 +2741,12 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2736
2741
}
2737
2742
pmaxy = maxy ;
2738
2743
/* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
2739
- if (miny < 0 ) {
2740
- miny = 0 ;
2744
+ /* 2.0.26: clipping rectangle is even better */
2745
+ if (miny < im -> cy1 ) {
2746
+ miny = im -> cy1 ;
2741
2747
}
2742
- if (maxy >= gdImageSY ( im ) ) {
2743
- maxy = gdImageSY ( im ) - 1 ;
2748
+ if (maxy > im -> cy2 ) {
2749
+ maxy = im -> cy2 ;
2744
2750
}
2745
2751
2746
2752
/* Fix in 1.3: count a vertex only once */
@@ -2774,9 +2780,17 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
2774
2780
* that Polygon and FilledPolygon for the same set of points have the
2775
2781
* same footprint.
2776
2782
*/
2777
- if (y >= y1 && y < y2 ) {
2778
- im -> polyInts [ints ++ ] = (float ) ((y - y1 ) * (x2 - x1 )) / (float ) (y2 - y1 ) + 0.5 + x1 ;
2779
- } else if (y == pmaxy && y == y2 ) {
2783
+ if ((y >= y1 ) && (y < y2 )) {
2784
+ if ((y1 > 0 && y < INT_MIN + y1 ) ||
2785
+ (y1 < 0 && y > INT_MAX + y1 ) ||
2786
+ (x1 > 0 && x2 < INT_MIN + x1 ) ||
2787
+ (x1 < 0 && x2 > INT_MAX + x1 ) ||
2788
+ overflow2 ((y - y1 ), (x2 - x1 ))) {
2789
+ continue ;
2790
+ }
2791
+ im -> polyInts [ints ++ ] = (int ) ((float ) ((y - y1 ) * (x2 - x1 )) /
2792
+ (float ) (y2 - y1 ) + 0.5 + x1 );
2793
+ } else if ((y == pmaxy ) && (y == y2 )) {
2780
2794
im -> polyInts [ints ++ ] = x2 ;
2781
2795
}
2782
2796
}
0 commit comments