From 44fa0b0f311beee4bfcbdb954d61f0c9a8395a96 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 19 Jan 2019 10:03:11 +0100 Subject: [PATCH] Fix #77479: imagewbmp() segfaults with very large images We must not proceed working with the Wbmp structure, if it hasn't been allocated. --- NEWS | 1 + ext/gd/libgd/gd_wbmp.c | 1 + ext/gd/tests/bug77479.phpt | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 ext/gd/tests/bug77479.phpt diff --git a/NEWS b/NEWS index d337e7f3c8..31e73b5ecc 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS . Fixed bug #73614 (gdImageFilledArc() doesn't properly draw pies). (cmb) . Fixed bug #77272 (imagescale() may return image resource on failure). (cmb) . Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb) + . Fixed bug #77479 (imagewbmp() segfaults with very large images). (cmb) - Mbstring: . Fixed bug #77454 (mb_scrub() silently truncates after a null byte). diff --git a/ext/gd/libgd/gd_wbmp.c b/ext/gd/libgd/gd_wbmp.c index 7b946aad2f..55ced3443d 100644 --- a/ext/gd/libgd/gd_wbmp.c +++ b/ext/gd/libgd/gd_wbmp.c @@ -100,6 +100,7 @@ void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out) /* create the WBMP */ if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) { gd_error("Could not create WBMP"); + return; } /* fill up the WBMP structure */ diff --git a/ext/gd/tests/bug77479.phpt b/ext/gd/tests/bug77479.phpt new file mode 100644 index 0000000000..9441e38d3e --- /dev/null +++ b/ext/gd/tests/bug77479.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #77479 (imagewbmp() segfaults with very large image) +--SKIPIF-- + +--INI-- +memory_limit=-1 +--FILE-- + +===DONE=== +--EXPECTF-- +Warning: imagewbmp(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully + in %s on line %d + +Warning: imagewbmp(): Could not create WBMP in %s on line %d +===DONE=== +--CLEAN-- + -- 2.40.0