pajoye Sun Dec 10 01:28:01 2006 UTC
Added files:
/php-src/ext/gd/tests bug39780.png bug39780.phpt
Modified files:
/php-src/ext/gd gd.c
/php-src/ext/gd/libgd gd_png.c
Log:
- #39780, PNG image with CRC/data error raises fatal error
http://cvs.php.net/viewvc.cgi/php-src/ext/gd/gd.c?r1=1.361&r2=1.362&diff_format=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.361 php-src/ext/gd/gd.c:1.362
--- php-src/ext/gd/gd.c:1.361 Tue Oct 31 22:13:09 2006
+++ php-src/ext/gd/gd.c Sun Dec 10 01:28:01 2006
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gd.c,v 1.361 2006/10/31 22:13:09 nlopess Exp $ */
+/* $Id: gd.c,v 1.362 2006/12/10 01:28:01 pajoye Exp $ */
/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
Cold Spring Harbor Labs. */
@@ -2016,6 +2016,7 @@
im = (*ioctx_func_p)(io_ctx);
if (!im) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not
in '%s' format", tn);
+ io_ctx->gd_free(io_ctx);
return NULL;
}
http://cvs.php.net/viewvc.cgi/php-src/ext/gd/libgd/gd_png.c?r1=1.22&r2=1.23&diff_format=u
Index: php-src/ext/gd/libgd/gd_png.c
diff -u php-src/ext/gd/libgd/gd_png.c:1.22 php-src/ext/gd/libgd/gd_png.c:1.23
--- php-src/ext/gd/libgd/gd_png.c:1.22 Sun Nov 5 15:06:50 2006
+++ php-src/ext/gd/libgd/gd_png.c Sun Dec 10 01:28:01 2006
@@ -58,7 +58,7 @@
* been defined.
*/
- php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s", msg);
+ php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg);
jmpbuf_ptr = png_get_error_ptr (png_ptr);
if (jmpbuf_ptr == NULL) { /* we are completely hosed now */
@@ -128,7 +128,6 @@
/* GRR: isn't sizeof(infile) equal to the size of the pointer? */
memset (sig, 0, sizeof(sig));
-
/* first do a quick check that the file really is a PNG image; could
* have used slightly more general png_sig_cmp() function instead
*/
@@ -201,6 +200,23 @@
png_set_packing (png_ptr); /* expand to 1 byte per pixel */
}
+ /* setjmp() must be called in every non-callback function that calls a
+ * PNG-reading libpng function
+ */
+#ifndef PNG_SETJMP_NOT_SUPPORTED
+ if (setjmp(gdPngJmpbufStruct.jmpbuf)) {
+ php_gd_error("gd-png error: setjmp returns error condition");
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+ gdFree(image_data);
+ gdFree(row_pointers);
+ if (im) {
+ gdImageDestroy(im);
+ }
+ return NULL;
+ }
+#endif
+
+
switch (color_type) {
case PNG_COLOR_TYPE_PALETTE:
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
http://cvs.php.net/viewvc.cgi/php-src/ext/gd/tests/bug39780.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/bug39780.phpt
+++ php-src/ext/gd/tests/bug39780.phpt
--TEST--
Bug #39780 (PNG image with CRC/data error raises a fatal error)
--SKIPIF--
<?php
if (!extension_loaded('gd')) die("skip gd extension not available\n");
if (!GD_BUNDLED) die('skip external GD libraries always fail');
?>
--FILE--
<?php
$im = imagecreatefrompng(dirname(__FILE__) . '/bug39780.png');
var_dump($im);
?>
--EXPECTF--
Warning: imagecreatefrompng(): gd-png: fatal libpng error: IDAT: CRC error in
%s on line %d
Warning: imagecreatefrompng(): gd-png error: setjmp returns error condition in
%s on line %d
Warning: imagecreatefrompng(): '%s' is not a valid PNG file in %s on line %d
bool(false)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php