Skip to content

Fix #71316: libpng warning from imagecreatefromstring #7615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ext/gd/libgd/gd_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ static void gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)

longjmp (jmpbuf_ptr->jmpbuf, 1);
}

static void gdPngWarningHandler (png_structp png_ptr, png_const_charp msg)
{
gd_error_ex(GD_WARNING, "gd-png: libpng warning: %s", msg);
}
#endif

static void gdPngReadData (png_structp png_ptr, png_bytep data, png_size_t length)
Expand Down Expand Up @@ -152,7 +157,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
}

#ifdef PNG_SETJMP_SUPPORTED
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbw, gdPngErrorHandler, NULL);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbw, gdPngErrorHandler, gdPngWarningHandler);
#else
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
Expand Down Expand Up @@ -494,7 +499,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte
#ifdef PNG_SETJMP_SUPPORTED
jmpbuf_wrapper jbw;

png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &jbw, gdPngErrorHandler, NULL);
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &jbw, gdPngErrorHandler, gdPngWarningHandler);
#else
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
Expand Down
18 changes: 18 additions & 0 deletions ext/gd/tests/bug71316.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug #71316 (libpng warning from imagecreatefromstring)
--SKIPIF--
<?php
if (!extension_loaded("gd")) die("skip gd extension not available");
if (!(imagetypes() & IMG_PNG)) die("skip PNG support not available");
if (!GD_BUNDLED && version_compare(GD_VERSION, "2.3.3", '<=')) {
die("skip test requires GD > 2.3.3");
}
?>
--FILE--
<?php
var_dump(
@imagecreatefrompng(__DIR__ . '/bug71316.png')
);
?>
--EXPECTF--
resource(%d) of type (gd)
Binary file added ext/gd/tests/bug71316.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.