fix possible SEGV by negatiev num of points

master
tabe 2010-01-14 19:10:57 +09:00
parent 1ad34e9c8c
commit 5876dc8ef4
33 changed files with 435 additions and 3 deletions

View File

@ -3147,7 +3147,7 @@ fail:
BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
{
if (!n)
if (n <= 0)
{
return;
}
@ -3161,7 +3161,7 @@ BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
{
int i;
int lx, ly;
if (!n)
if (n <= 0)
{
return;
}
@ -3203,7 +3203,7 @@ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int
int ind1, ind2;
int ints;
int fill_color;
if (!n)
if (n <= 0)
{
return;
}

View File

@ -38,10 +38,13 @@ if (BUILD_TEST)
#gdimageellipse
gdimagefill
gdimagefilledellipse
gdimagefilledpolygon
gdimagefilledrectangle
gdimagefilltoborder
gdimageline
gdimageopenpolygon
gdimagepixelate
gdimagepolygon
gdimagerectangle
gdimagescatterex
gdimagesetpixel

View File

@ -17,10 +17,13 @@ SUBDIRS = gdtest \
gdimagecopyrotated \
gdimagefill \
gdimagefilledellipse \
gdimagefilledpolygon \
gdimagefilledrectangle \
gdimagefilltoborder \
gdimageline \
gdimageopenpolygon \
gdimagepixelate \
gdimagepolygon \
gdimagerectangle \
gdimagescatterex \
gdimagesetpixel \

View File

@ -0,0 +1,13 @@
SET(TESTS_FILES
gdimagefilledpolygon0
gdimagefilledpolygon1
gdimagefilledpolygon2
gdimagefilledpolygon3
)
FOREACH(test_name ${TESTS_FILES})
add_executable(${test_name} "${test_name}.c")
target_link_libraries (${test_name} ${GDTESTS_TARGET_LINK})
get_target_property(test_path ${test_name} LOCATION)
ADD_TEST(${test_name} ${test_path})
ENDFOREACH(test_name)

View File

@ -0,0 +1,11 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = CMakeLists.txt \
gdimagefilledpolygon0.c \
gdimagefilledpolygon0.png \
gdimagefilledpolygon1.c \
gdimagefilledpolygon1.png \
gdimagefilledpolygon2.c \
gdimagefilledpolygon2.png \
gdimagefilledpolygon3.c \
gdimagefilledpolygon3.png

View File

@ -0,0 +1,22 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
gdImageFilledPolygon(im, NULL, 0, black); /* no effect */
gdImageFilledPolygon(im, NULL, -1, black); /* no effect */
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagefilledpolygon/gdimagefilledpolygon0.png", im);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,30 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
gdImageFilledPolygon(im, points, 1, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagefilledpolygon/gdimagefilledpolygon1.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,32 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
gdImageFilledPolygon(im, points, 2, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagefilledpolygon/gdimagefilledpolygon2.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

View File

@ -0,0 +1,34 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
points[2].x = 90;
points[2].y = 30;
gdImageFilledPolygon(im, points, 3, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagefilledpolygon/gdimagefilledpolygon3.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

View File

@ -0,0 +1,13 @@
SET(TESTS_FILES
gdimageopenpolygon0
gdimageopenpolygon1
gdimageopenpolygon2
gdimageopenpolygon3
)
FOREACH(test_name ${TESTS_FILES})
add_executable(${test_name} "${test_name}.c")
target_link_libraries (${test_name} ${GDTESTS_TARGET_LINK})
get_target_property(test_path ${test_name} LOCATION)
ADD_TEST(${test_name} ${test_path})
ENDFOREACH(test_name)

View File

@ -0,0 +1,11 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = CMakeLists.txt \
gdimageopenpolygon0.c \
gdimageopenpolygon0.png \
gdimageopenpolygon1.c \
gdimageopenpolygon1.png \
gdimageopenpolygon2.c \
gdimageopenpolygon2.png \
gdimageopenpolygon3.c \
gdimageopenpolygon3.png

View File

@ -0,0 +1,22 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
gdImageOpenPolygon(im, NULL, 0, black); /* no effect */
gdImageOpenPolygon(im, NULL, -1, black); /* no effect */
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimageopenpolygon/gdimageopenpolygon0.png", im);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,30 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
gdImageOpenPolygon(im, points, 1, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimageopenpolygon/gdimageopenpolygon1.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,32 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
gdImageOpenPolygon(im, points, 2, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimageopenpolygon/gdimageopenpolygon2.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

View File

@ -0,0 +1,34 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
points[2].x = 90;
points[2].y = 30;
gdImageOpenPolygon(im, points, 3, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimageopenpolygon/gdimageopenpolygon3.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

View File

@ -0,0 +1,13 @@
SET(TESTS_FILES
gdimagepolygon0
gdimagepolygon1
gdimagepolygon2
gdimagepolygon3
)
FOREACH(test_name ${TESTS_FILES})
add_executable(${test_name} "${test_name}.c")
target_link_libraries (${test_name} ${GDTESTS_TARGET_LINK})
get_target_property(test_path ${test_name} LOCATION)
ADD_TEST(${test_name} ${test_path})
ENDFOREACH(test_name)

View File

@ -0,0 +1,11 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = CMakeLists.txt \
gdimagepolygon0.c \
gdimagepolygon0.png \
gdimagepolygon1.c \
gdimagepolygon1.png \
gdimagepolygon2.c \
gdimagepolygon2.png \
gdimagepolygon3.c \
gdimagepolygon3.png

View File

@ -0,0 +1,22 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
gdImagePolygon(im, NULL, 0, black); /* no effect */
gdImagePolygon(im, NULL, -1, black); /* no effect */
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagepolygon/gdimagepolygon0.png", im);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

View File

@ -0,0 +1,30 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
gdImagePolygon(im, points, 1, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagepolygon/gdimagepolygon1.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

View File

@ -0,0 +1,32 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
gdImagePolygon(im, points, 2, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagepolygon/gdimagepolygon2.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

View File

@ -0,0 +1,34 @@
#include <stdlib.h>
#include "gd.h"
#include "gdtest.h"
int
main(void)
{
gdImagePtr im;
int white, black, r;
gdPointPtr points;
im = gdImageCreate(100, 100);
if (!im) exit(EXIT_FAILURE);
white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageFilledRectangle(im, 0, 0, 99, 99, white);
points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
if (!points) {
gdImageDestroy(im);
exit(EXIT_FAILURE);
}
points[0].x = 10;
points[0].y = 10;
points[1].x = 50;
points[1].y = 70;
points[2].x = 90;
points[2].y = 30;
gdImagePolygon(im, points, 3, black);
r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagepolygon/gdimagepolygon3.png", im);
gdFree(points);
gdImageDestroy(im);
if (!r) exit(EXIT_FAILURE);
return EXIT_SUCCESS;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B