Skip to content

Commit

Permalink
Fix #77391: 1bpp BMPs may fail to be loaded
Browse files Browse the repository at this point in the history
We port the upstream fix[1].

[1] <libgd/libgd@d085913>
  • Loading branch information
cmb69 committed Dec 31, 2018
1 parent 687dad3 commit b0cfa28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2019, PHP 7.2.15

- GD:
. Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb)

- Sockets:
. Fixed bug #76839 (socket_recvfrom may return an invalid 'from' address
on MacOS). (Michael Meyer)
Expand Down
4 changes: 2 additions & 2 deletions ext/gd/libgd/gd_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
padding = ((int)ceil(0.1 * info->width)) % 4;
/* The line must be aligned on a 32 bits word, else it is padded with zeros */
padding = (info->width + 7) / 8 % 4;
if (padding) {
padding = 4 - padding;
}
Expand Down
Binary file added ext/gd/tests/bug77391.bmp
Binary file not shown.
15 changes: 15 additions & 0 deletions ext/gd/tests/bug77391.phpt
Original file line number Diff line number Diff line change
@@ -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===

0 comments on commit b0cfa28

Please sign in to comment.