Anonymous avatar Anonymous committed 9da2955

fix possible SEGV by negatiev num of points

Comments (0)

Files changed (33)

 
 BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
 {
-  if (!n)
+  if (n <= 0)
     {
       return;
     }
 {
   int i;
   int lx, ly;
-  if (!n)
+  if (n <= 0)
     {
       return;
     }
   int ind1, ind2;
   int ints;
   int fill_color;
-  if (!n)
+  if (n <= 0)
     {
       return;
     }

src/tests/CMakeLists.txt

 		#gdimageellipse
 		gdimagefill
 		gdimagefilledellipse
+		gdimagefilledpolygon
 		gdimagefilledrectangle
 		gdimagefilltoborder
 		gdimageline
+		gdimageopenpolygon
+		gdimagepolygon
 		gdimagerectangle
 		gdimagesetpixel
 		gdimagestringft

src/tests/Makefile.am

 		gdimagecopyrotated \
 		gdimagefill \
 		gdimagefilledellipse \
+		gdimagefilledpolygon \
 		gdimagefilledrectangle \
 		gdimagefilltoborder \
 		gdimageline \
+		gdimageopenpolygon \
+		gdimagepolygon \
 		gdimagerectangle \
 		gdimagesetpixel \
 		gdimagestringft \

src/tests/gdimagefilledpolygon/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagefilledpolygon0
+	gdimagefilledpolygon1
+	gdimagefilledpolygon2
+	gdimagefilledpolygon3
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

src/tests/gdimagefilledpolygon/Makefile.am

+## 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

src/tests/gdimagefilledpolygon/gdimagefilledpolygon0.c

+#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;
+}
Add a comment to this file

src/tests/gdimagefilledpolygon/gdimagefilledpolygon0.png

Added
New image

src/tests/gdimagefilledpolygon/gdimagefilledpolygon1.c

+#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;
+}
Add a comment to this file

src/tests/gdimagefilledpolygon/gdimagefilledpolygon1.png

Added
New image

src/tests/gdimagefilledpolygon/gdimagefilledpolygon2.c

+#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;
+}
Add a comment to this file

src/tests/gdimagefilledpolygon/gdimagefilledpolygon2.png

Added
New image

src/tests/gdimagefilledpolygon/gdimagefilledpolygon3.c

+#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;
+}
Add a comment to this file

src/tests/gdimagefilledpolygon/gdimagefilledpolygon3.png

Added
New image

src/tests/gdimageopenpolygon/CMakeLists.txt

+SET(TESTS_FILES
+	gdimageopenpolygon0
+	gdimageopenpolygon1
+	gdimageopenpolygon2
+	gdimageopenpolygon3
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

src/tests/gdimageopenpolygon/Makefile.am

+## 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

src/tests/gdimageopenpolygon/gdimageopenpolygon0.c

+#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;
+}
Add a comment to this file

src/tests/gdimageopenpolygon/gdimageopenpolygon0.png

Added
New image

src/tests/gdimageopenpolygon/gdimageopenpolygon1.c

+#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;
+}
Add a comment to this file

src/tests/gdimageopenpolygon/gdimageopenpolygon1.png

Added
New image

src/tests/gdimageopenpolygon/gdimageopenpolygon2.c

+#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;
+}
Add a comment to this file

src/tests/gdimageopenpolygon/gdimageopenpolygon2.png

Added
New image

src/tests/gdimageopenpolygon/gdimageopenpolygon3.c

+#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;
+}
Add a comment to this file

src/tests/gdimageopenpolygon/gdimageopenpolygon3.png

Added
New image

src/tests/gdimagepolygon/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagepolygon0
+	gdimagepolygon1
+	gdimagepolygon2
+	gdimagepolygon3
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	get_target_property(test_path ${test_name} LOCATION)
+	ADD_TEST(${test_name} ${test_path})
+ENDFOREACH(test_name)

src/tests/gdimagepolygon/Makefile.am

+## 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

src/tests/gdimagepolygon/gdimagepolygon0.c

+#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;
+}
Add a comment to this file

src/tests/gdimagepolygon/gdimagepolygon0.png

Added
New image

src/tests/gdimagepolygon/gdimagepolygon1.c

+#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;
+}
Add a comment to this file

src/tests/gdimagepolygon/gdimagepolygon1.png

Added
New image

src/tests/gdimagepolygon/gdimagepolygon2.c

+#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;
+}
Add a comment to this file

src/tests/gdimagepolygon/gdimagepolygon2.png

Added
New image

src/tests/gdimagepolygon/gdimagepolygon3.c

+#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;
+}
Add a comment to this file

src/tests/gdimagepolygon/gdimagepolygon3.png

Added
New image
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.