diff --git a/ext/gd/libgd/gd_xbm.c b/ext/gd/libgd/gd_xbm.c index 4683f023d33..c1d91043d35 100644 --- a/ext/gd/libgd/gd_xbm.c +++ b/ext/gd/libgd/gd_xbm.c @@ -78,7 +78,7 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd) max_bit = 32768; } if (max_bit) { - bytes = (width * height / 8) + 1; + bytes = (width + 7) / 8 * height; if (!bytes) { return 0; } diff --git a/ext/gd/tests/bug73968.phpt b/ext/gd/tests/bug73968.phpt new file mode 100644 index 00000000000..fd17fe26ba9 --- /dev/null +++ b/ext/gd/tests/bug73968.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #73968 (Premature failing of XBM reading) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +resource(%d) of type (gd) +===DONE=== diff --git a/ext/gd/tests/bug73968.xbm b/ext/gd/tests/bug73968.xbm new file mode 100644 index 00000000000..f427d86a54b --- /dev/null +++ b/ext/gd/tests/bug73968.xbm @@ -0,0 +1,5 @@ +#define test_width 10 +#define test_height 10 +static unsigned char test_bits[] = { + 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, + 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00}; diff --git a/ext/gd/tests/libgd00094-mb.phpt b/ext/gd/tests/libgd00094-mb.phpt index a5e55baa96c..c18b4fd3d16 100644 --- a/ext/gd/tests/libgd00094-mb.phpt +++ b/ext/gd/tests/libgd00094-mb.phpt @@ -11,9 +11,6 @@ $im = imagecreatefromxbm(dirname(__FILE__) . '/libgd00094私はガラスを食 var_dump($im); ?> --EXPECTF-- -Warning: imagecreatefromxbm(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully - in %slibgd00094-mb.php on line %d - Warning: imagecreatefromxbm(): '%slibgd00094私はガラスを食べられます.xbm' is not a valid XBM file in %slibgd00094-mb.php on line %d bool(false) diff --git a/ext/gd/tests/libgd00094.phpt b/ext/gd/tests/libgd00094.phpt index d1d68eab041..d06afc47294 100644 --- a/ext/gd/tests/libgd00094.phpt +++ b/ext/gd/tests/libgd00094.phpt @@ -11,9 +11,6 @@ $im = imagecreatefromxbm(dirname(__FILE__) . '/libgd00094.xbm'); var_dump($im); ?> --EXPECTF-- -Warning: imagecreatefromxbm(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully - in %slibgd00094.php on line %d - Warning: imagecreatefromxbm(): '%slibgd00094.xbm' is not a valid XBM file in %slibgd00094.php on line %d bool(false)