Skip to content

Fix: bitmaps with BITMAPV3INFOHEADER cannot be imported #11027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: PHP-8.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/gd/libgd/bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern "C" {
#define BMP_WINDOWS_V3 40
#define BMP_OS2_V1 12
#define BMP_OS2_V2 64
#define BMP_WINDOWS_V3INFO 56
#define BMP_WINDOWS_V4 108
#define BMP_WINDOWS_V5 124

Expand Down
9 changes: 7 additions & 2 deletions ext/gd/libgd/gd_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ static int bmp_read_info(gdIOCtx *infile, bmp_info_t *info)
switch (info->len) {
/* For now treat Windows v4 + v5 as v3 */
case BMP_WINDOWS_V3:
case BMP_WINDOWS_V3INFO:
case BMP_WINDOWS_V4:
case BMP_WINDOWS_V5:
BMP_DEBUG(printf("Reading Windows Header\n"));
Expand Down Expand Up @@ -685,8 +686,12 @@ static int bmp_read_direct(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, b
BMP_DEBUG(printf("Bitfield compression isn't supported for 24-bit\n"));
return 1;
}
BMP_DEBUG(printf("Currently no bitfield support\n"));
return 1;
/* For 32 BPP images, the bitfields do not contain any useful information. They can be safely skipped. */
if (info->depth != 32) {
BMP_DEBUG(printf("Currently no bitfield support\n"));
return 1;
}

break;

case BMP_BI_RLE8:
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
imagecreatefrombmp() - test image with BITMAPV3INFOHEADER, 32bpp and (unnecessary) bitfields
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!(imagetypes() & IMG_BMP)) die('skip BMP support required');
?>
--FILE--
<?php
// create an image from a BMP file
$im = imagecreatefrombmp(__DIR__ . '/imagecreatefrombmp-v3info-32bpp-bitfields-11027-input.bmp');

include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecreatefrombmp-v3info-32bpp-bitfields-11027-output.png', $im);
?>
--EXPECT--
The images are equal.
Binary file not shown.
18 changes: 18 additions & 0 deletions ext/gd/tests/imagecreatefrombmp-v5-32bpp-bitfields-11027.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
imagecreatefrombmp() - test image with BITMAPV5HEADER, 32bpp and (unnecessary) bitfields
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!(imagetypes() & IMG_BMP)) die('skip BMP support required');
?>
--FILE--
<?php
// create an image from a BMP file
$im = imagecreatefrombmp(__DIR__ . '/imagecreatefrombmp-v5-32bpp-bitfields-11027-input.bmp');

include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecreatefrombmp-v3info-32bpp-bitfields-11027-output.png', $im);
?>
--EXPECT--
The images are equal.