Fix #77391: 1bpp BMPs may fail to be loaded

We port the upstream fix[1].

[1] <d0859134fc>
This commit is contained in:
Christoph M. Becker 2018-12-31 20:45:47 +01:00
parent 687dad3674
commit b0cfa28d6d
4 changed files with 20 additions and 2 deletions

3
NEWS
View file

@ -2,6 +2,9 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2019, PHP 7.2.15 ?? ??? 2019, PHP 7.2.15
- GD:
. Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb)
- Sockets: - Sockets:
. Fixed bug #76839 (socket_recvfrom may return an invalid 'from' address . Fixed bug #76839 (socket_recvfrom may return an invalid 'from' address
on MacOS). (Michael Meyer) on MacOS). (Michael Meyer)

View file

@ -813,8 +813,8 @@ static int bmp_read_1bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp
} }
} }
/* The line must be divisible by 4, else its padded with NULLs */ /* The line must be aligned on a 32 bits word, else it is padded with zeros */
padding = ((int)ceil(0.1 * info->width)) % 4; padding = (info->width + 7) / 8 % 4;
if (padding) { if (padding) {
padding = 4 - padding; padding = 4 - padding;
} }

BIN
ext/gd/tests/bug77391.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

View file

@ -0,0 +1,15 @@
--TEST--
Bug #77391 (1bpp BMPs may fail to be loaded)
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstream not yet fixed');
?>
--FILE--
<?php
var_dump(imagecreatefrombmp(__DIR__ . '/bug77391.bmp'));
?>
===DONE===
--EXPECTF--
resource(%d) of type (gd)
===DONE===