Hi all, I've created a simple patch for Bug #45799 [1]
It employs a simple check to see if there are any colors associated with the image before outputting the PNG header. The patch is against CVS 5.3, shown below for convenience. I can create patches for the other branches if required. The tests pass. This is my first patch to PHP, so I've done anything wrong, give me some pointers as to how to fix it. Thanks, -- Martin McNickle [1] http://bugs.php.net/bug.php?id=45799 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);
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);
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php