Skip to content

Commit 44fa0b0

Browse files
committed
Fix #77479: imagewbmp() segfaults with very large images
We must not proceed working with the Wbmp structure, if it hasn't been allocated.
1 parent dbe7f2a commit 44fa0b0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PHP NEWS
1414
. Fixed bug #73614 (gdImageFilledArc() doesn't properly draw pies). (cmb)
1515
. Fixed bug #77272 (imagescale() may return image resource on failure). (cmb)
1616
. Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb)
17+
. Fixed bug #77479 (imagewbmp() segfaults with very large images). (cmb)
1718

1819
- Mbstring:
1920
. Fixed bug #77454 (mb_scrub() silently truncates after a null byte).

ext/gd/libgd/gd_wbmp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
100100
/* create the WBMP */
101101
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
102102
gd_error("Could not create WBMP");
103+
return;
103104
}
104105

105106
/* fill up the WBMP structure */

ext/gd/tests/bug77479.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #77479 (imagewbmp() segfaults with very large image)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
7+
?>
8+
--INI--
9+
memory_limit=-1
10+
--FILE--
11+
<?php
12+
$im = imagecreate(40000, 20000);
13+
imagecolorallocate($im, 0, 0, 0);
14+
imagewbmp($im, __DIR__ . '/77479.wbmp');
15+
?>
16+
===DONE===
17+
--EXPECTF--
18+
Warning: imagewbmp(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
19+
in %s on line %d
20+
21+
Warning: imagewbmp(): Could not create WBMP in %s on line %d
22+
===DONE===
23+
--CLEAN--
24+
<?php
25+
@unlink(__DIR__ . '/77479.wbmp');
26+
?>

0 commit comments

Comments
 (0)