Commits

Anonymous committed 8dbae8d

-MFB, #113, gdImageColorTransparent can write outside buffer

  • Participants
  • Parent commits ca3b87a
  • Branches GD-2.0

Comments (0)

Files changed (4)

 {
   if (!im->trueColor)
     {
+	if((color < -1) || (color >= gdMaxColors)) {
+		return;
+	}
       if (im->transparent != -1)
 	{
 	  im->alpha[im->transparent] = gdAlphaOpaque;

src/tests/CMakeLists.txt

 		gdimagecolorexact
 		gdimagecolorresolve
 		gdimagecolordeallocate
+		gdimagecolortransparent
 		#gdimageellipse
 		gdimageline
 		gdimagefilledellipse

src/tests/gdimagecolortransparent/CMakeLists.txt

+SET(TESTS_FILES
+	gdimagecolortransparent
+)
+
+FOREACH(test_name ${TESTS_FILES})
+	add_executable(${test_name} "${test_name}.c")
+	target_link_libraries (${test_name} gdTest ${GD_LIB})
+	ADD_TEST("${test_name}" ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)

src/tests/gdimagecolortransparent/gdimagecolortransparent.c

+#include <gd.h>
+#include <stdio.h>
+#include "gdtest.h"
+
+int main()
+{
+	gdImagePtr im;
+	int error = 0, pos;
+
+	pos = gdMaxColors;
+
+	im = gdImageCreate(1,1);
+
+	gdImageColorTransparent(im, pos);
+
+	if(im->transparent == pos) {
+		error = -1;
+	}
+
+	pos = -2;
+
+	gdImageColorTransparent(im, pos);
+
+	if(im->transparent == pos) {
+		error = -1;
+	}
+
+	gdImageDestroy(im);
+
+	return error;
+}