Anonymous avatar Anonymous committed 627e0b8

MFH: fixed FS#193

Comments (0)

Files changed (4)

 	      ++colors;
 	    }
 	}
+	  if (colors == 0) {
+		  fprintf(stderr, "gd-png error: no colors in palette\n");
+		  goto bail;
+	  }
       if (colors < im->colorsTotal)
 	{
 	  remap = TRUE;
 	}
     }
   /* 1.6.3: maybe we should give that memory BACK! TBB */
+ bail:
   png_destroy_write_struct (&png_ptr, &info_ptr);
 }
 

tests/png/CMakeLists.txt

 	bug00033
 	bug00086
 	bug00088
+	bug00193
 )
 
 FOREACH(test_name ${TESTS_FILES})

tests/png/Makefile.am

 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
 
-EXTRA_DIST = CMakeLists.txt bug00011.c bug00033.png bug00088_1_exp.png bug00088_2_exp.png bug00088.c bug00033.c bug00086.c bug00088_1.png bug00088_2.png emptyfile
+EXTRA_DIST = CMakeLists.txt bug00011.c bug00033.png bug00088_1_exp.png bug00088_2_exp.png bug00088.c bug00033.c bug00086.c bug00088_1.png bug00088_2.png bug00193.c emptyfile

tests/png/bug00193.c

+#include "gd.h"
+#include <stdio.h>
+#include "gdtest.h"
+
+static gdImagePtr im;
+
+#define TERMINATE(ctx, status) do {				\
+		gdFree(ctx);							\
+		gdImageDestroy(im);						\
+		exit(status);							\
+	} while (0)
+
+static void
+failPutC(gdIOCtxPtr ctx, int c)
+{
+	TERMINATE(ctx, 1);
+}
+
+static int
+failPutBuf(gdIOCtxPtr ctx, const void * data, int size)
+{
+	TERMINATE(ctx, 1);
+	return -1;
+}
+
+int main()
+{
+	gdIOCtxPtr ctx;
+
+	im = gdImageCreate(100, 100);
+	ctx = (gdIOCtxPtr)gdMalloc(sizeof(gdIOCtx));
+	ctx->putC   = failPutC;
+	ctx->putBuf = failPutBuf;
+	gdImagePngCtx(im, ctx);
+	TERMINATE(ctx, 0);
+	return 0;
+}
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.