Skip to content

Commit f67d599

Browse files
committed
Fix #73968: Premature failing of XBM reading
We must take into account the line padding, when we're reading XBM files. We deliberately ignore the potential integer overflow here, because that would be caught by gdImageCreate() or even earlier if `bytes==0`, what happens in libgd00094.phpt which we adapt accordingly.
1 parent 8da8756 commit f67d599

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
. Fixed bug #67583 (double fastcgi_end_request on max_children limit).
1616
(Dmitry Saprykin)
1717

18+
- GD:
19+
. Fixed bug #73968 (Premature failing of XBM reading). (cmb)
20+
1821
- GMP:
1922
. Fixed bug #69993 (test for gmp.h needs to test machine includes).
2023
(Jordan Gigov)

ext/gd/libgd/xbm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd)
7777
max_bit = 32768;
7878
}
7979
if (max_bit) {
80-
bytes = (width * height / 8) + 1;
80+
bytes = (width + 7) / 8 * height;
8181
if (!bytes) {
8282
return 0;
8383
}

ext/gd/tests/bug73968.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #73968 (Premature failing of XBM reading)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$im = imagecreatefromxbm(__DIR__ . DIRECTORY_SEPARATOR . 'bug73968.xbm');
10+
var_dump($im);
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
resource(%d) of type (gd)
15+
===DONE===

ext/gd/tests/bug73968.xbm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define test_width 10
2+
#define test_height 10
3+
static unsigned char test_bits[] = {
4+
0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00,
5+
0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00};

ext/gd/tests/libgd00094.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ $im = imagecreatefromxbm(dirname(__FILE__) . '/libgd00094.xbm');
1111
var_dump($im);
1212
?>
1313
--EXPECTF--
14-
Warning: imagecreatefromxbm(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
15-
in %slibgd00094.php on line %d
16-
1714
Warning: imagecreatefromxbm(): '%slibgd00094.xbm' is not a valid XBM file in %slibgd00094.php on line %d
1815
bool(false)
1916

0 commit comments

Comments
 (0)