From 93b4f49879347a88e583e2a86732ce4e969ccfe0 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Thu, 6 Apr 2023 23:20:20 +0200 Subject: [PATCH 1/2] Fix: bitmaps with BITMAPV3INFOHEADER cannot be imported These files are reportedly written by Photoshop and based on a specification by Microsoft. More information can be found here: https://en.wikipedia.org/wiki/BMP_file_format#DIB_header_(bitmap_information_header) https://formats.kaitai.io/bmp/ https://web.archive.org/web/20150127132443/https://forums.adobe.com/message/3272950 --- ext/gd/libgd/bmp.h | 1 + ext/gd/libgd/gd_bmp.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/gd/libgd/bmp.h b/ext/gd/libgd/bmp.h index cecde0383f53..4367c36d043b 100644 --- a/ext/gd/libgd/bmp.h +++ b/ext/gd/libgd/bmp.h @@ -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 diff --git a/ext/gd/libgd/gd_bmp.c b/ext/gd/libgd/gd_bmp.c index 00903d5ff8dc..4d193c3a1113 100644 --- a/ext/gd/libgd/gd_bmp.c +++ b/ext/gd/libgd/gd_bmp.c @@ -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")); @@ -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: From 0e13417e8cc6d4069dd303c9c0eae4f3320d7e93 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 7 Apr 2023 19:09:37 +0200 Subject: [PATCH 2/2] Add tests --- ...bmp-v3info-32bpp-bitfields-11027-input.bmp | Bin 0 -> 1414 bytes ...mp-v3info-32bpp-bitfields-11027-output.png | Bin 0 -> 830 bytes ...efrombmp-v3info-32bpp-bitfields-11027.phpt | 18 ++++++++++++++++++ ...frombmp-v5-32bpp-bitfields-11027-input.bmp | Bin 0 -> 1482 bytes ...reatefrombmp-v5-32bpp-bitfields-11027.phpt | 18 ++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-input.bmp create mode 100644 ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-output.png create mode 100644 ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027.phpt create mode 100644 ext/gd/tests/imagecreatefrombmp-v5-32bpp-bitfields-11027-input.bmp create mode 100644 ext/gd/tests/imagecreatefrombmp-v5-32bpp-bitfields-11027.phpt diff --git a/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-input.bmp b/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-input.bmp new file mode 100644 index 0000000000000000000000000000000000000000..994f35a96ead2d225bed72964c4b8b0ce67a0a85 GIT binary patch literal 1414 zcma)+Z)78R7{`0gy}CDNq!JNPB1(u5q9=rLkrU!V2%&@!LWB}RDJ6tbLI_I;O9`cu zO#U=&u4!|omAb8Jt&OU!RjX>Pb*k!^m!JDhdOdM&xiR1QKcDA$zRxrB(=Qv}%}tk| z#r8*`AB5(GzL{H?`&R5_abNoWS>p8Xg}J%s)i@^-Q~psh-6UU7+1ThKNy`7ya;nL! zR`M#P(k`{yhchTB$ETeq8C}G=#8f}ecoUhej03-e1JbXB9ctx># zOSSQZ?SYQp-$vThks3mpKJCG5PBy87OZpY>{D^>cOxS)-+%X~Nxu+O|*!s5m?iS34W%gvnFCJx)j{rXMc?P3}1{sJx2h+JQ z`l@NSV#Y3oZjel$g>-xYokUWwiaJ|H&W;|EYl!4MMOvC51@4h#9cx_2mDPne9TKJ< zDf2El`#uHd0Y&eKvV6>|=o_|Dm#Bqn2Gu*X?xTp+5i;icP-slQe8k}On34JxZFq;- zsbF<0*q53(F;3)?eQ07l{I4k literal 0 HcmV?d00001 diff --git a/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-output.png b/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027-output.png new file mode 100644 index 0000000000000000000000000000000000000000..e3d27ee538dea7e5db70fa05b06175fe81c12770 GIT binary patch literal 830 zcmV-E1Ht@>P)cT-0A$~0c zNg!_G#)Tlbiv$u~DdR#RM3|-ME`Ndsf{Y@Fn2mxivT!v^K@gH2YM5x!P4!f_i}4GY zvpSdayBF>epRccrq7X647-fu#$Pn3-0&|gb$(#m*TW`NEJ!DiWDqTLgRMZ)2ZS*#G zp5Vw9IsEkg$GQ+U8XffTRNs&b6irHc^3*e)+2+dk#@}81&;-~LKFQ-7C~6t2Wm;Rh zp+-0XJApbaZZI1_OR1I8##rYZkxR+<`<}TNjpBIx<@GJ$rHEQYqxDMzNk&8?f|XY*dMMm_^HmKvAOPYvGXY5=19)tL^^=%PaO(6o zAH3roqDM05TMQIXdDJ~I+k64JLass8_D471ExbqYNJ-=@QeWq6Gl!hhV9;Y0H~E-H zGRiv>osQm6pGL*7mNm%{$#GWW@~d~>kXFi|baXmAk#y=g9=VhYPJ!7nhe7@I)lbfC z>|hNzhUJ+v%Me5e2R`TrPoD*#nLXDXvl$M5xOPnu`N?E^D~Z9wqVW10&xv?(O~ybh~%{8Dzgg z2MNsg_jjk$MKkU8c2|Gj{%c{izklciGn5iaHJh79*8l+c6WpY&G87+|NB{r;07*qo IM6N<$f`7n%Gynhq literal 0 HcmV?d00001 diff --git a/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027.phpt b/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027.phpt new file mode 100644 index 000000000000..5f9762b2034a --- /dev/null +++ b/ext/gd/tests/imagecreatefrombmp-v3info-32bpp-bitfields-11027.phpt @@ -0,0 +1,18 @@ +--TEST-- +imagecreatefrombmp() - test image with BITMAPV3INFOHEADER, 32bpp and (unnecessary) bitfields +--EXTENSIONS-- +gd +--SKIPIF-- + +--FILE-- + +--EXPECT-- +The images are equal. diff --git a/ext/gd/tests/imagecreatefrombmp-v5-32bpp-bitfields-11027-input.bmp b/ext/gd/tests/imagecreatefrombmp-v5-32bpp-bitfields-11027-input.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1332fc4c93cb5fb71adc335790c1de5089474ebf GIT binary patch literal 1482 zcma)+e`F(R7{_~e?yvjjj8q~bN<;|}LX;53MqP*tIU$q~LWoe}La8eul%5bm31KOr zbdt%Brp+~NPFktkUbWUn)z+$2wbnXS>zF@3_fEPY)*d_Z%{w#i5*8MAbz&Y6zq^DF$H`~ihPNFf}3@-jD&HVKD!iN(4EL@!cy(HmEN{JhT6{nXhG z`2cUIPdGj#zI@Jd?uuOLmQwWt+g%N>w}G^wAytJ2+PDYPIa#D84(SivvweK#Apz?- z5!;Bg>z>@=1BInW%9)RBZ~RMVOE64z4Aut5`4(399==tLu;3@l8ml74yhFk1e)31J zPxnOcQ+m11>RO9Jp*x-ny|078t(dV(p&KN_dm#;vPa_%=tenP{p0lluLO}BK%p!FzXHHGx~ zJ`@_#DIC##KBTX{WYD|AXjd>h6|4(2>~bAfP{kW<5JbuA3V&Y;e{V_2 zyJUl1@=He)Qzukb&V*MZI?vxS=sXayh#uP%)`Twwk3w0lu^pjN3%?*$X zrv%F9gsLNvTaCE|Rd~_B8EoT;h@K~V1XhlTY@7)X>q2b|hJB329u~`=*la^wu5*08 zSA;@0#N&6Yto%cBa<13|FSbmr4iNYTe{r` Qq +--FILE-- + +--EXPECT-- +The images are equal.