Index: ext/gd/libgd/gd_png.c =================================================================== RCS file: /repository/php-src/ext/gd/libgd/gd_png.c,v retrieving revision 1.17.4.2.2.5.2.3 diff -u -r1.17.4.2.2.5.2.3 gd_png.c --- ext/gd/libgd/gd_png.c 14 Jan 2009 10:16:15 -0000 1.17.4.2.2.5.2.3 +++ ext/gd/libgd/gd_png.c 10 Mar 2009 11:12:02 -0000 @@ -650,6 +650,12 @@ png_set_PLTE(png_ptr, info_ptr, palette, colors); } + if (colors <= 0 && !im->trueColor) { + php_gd_error("gd-png error: Invalid number of colors in palette./martin"); + png_destroy_write_struct (&png_ptr, &info_ptr); + return; + } + /* write out the PNG header info (everything up to first IDAT) */ png_write_info(png_ptr, info_ptr);