Skip to content

Commit ee06ca8

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Fix #73968: Premature failing of XBM reading
2 parents 1c80737 + 7a2497b commit ee06ca8

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

ext/gd/libgd/gd_xbm.c

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

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-mb.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ $im = imagecreatefromxbm(dirname(__FILE__) . '/libgd00094私はガラスを食
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-mb.php on line %d
16-
1714
Warning: imagecreatefromxbm(): '%slibgd00094私はガラスを食べられます.xbm' is not a valid XBM file in %slibgd00094-mb.php on line %d
1815
bool(false)
1916

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)