Skip to content

Commit d4bd6fb

Browse files
committed
Fix #79615: Wrong GIF header written in GD GIFEncode
The color resolution is expected in bits 4-6 of the packed fields byte of the logical screen descriptor (byte 10 of the GIF data stream), according to the specification[1], section 18. [1] <https://www.w3.org/Graphics/GIF/spec-gif89a.txt>
1 parent 85ac564 commit d4bd6fb

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #79566 (Private SHM is not private on Windows). (cmb)
77
. Fixed bug #79489 (.user.ini does not inherit). (cmb)
88

9+
- GD:
10+
. Fixed bug #79615 (Wrong GIF header written in GD GIFEncode). (sageptr, cmb)
11+
912
- MySQLnd:
1013
. Fixed bug #79596 (MySQL FLOAT truncates to int some locales). (cmb)
1114

ext/gd/libgd/gd_gif_out.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ GIFEncode(gdIOCtxPtr fp, int GWidth, int GHeight, int GInterlace, int Background
319319
/*
320320
* OR in the resolution
321321
*/
322-
B |= (Resolution - 1) << 5;
322+
B |= (Resolution - 1) << 4;
323323

324324
/*
325325
* OR in the Bits per Pixel

ext/gd/tests/bug79615.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #79615 (Wrong GIF header written in GD GIFEncode)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$im = imagecreate(3, 3); // 3x3, 9 colors, 4 bits per pixel
10+
for ($x = 0; $x < 3; $x++) {
11+
for ($y = 0; $y < 3; $y++) {
12+
imagesetpixel($im, $x, $y, imagecolorallocate($im, $x, $y, 0));
13+
}
14+
}
15+
ob_start();
16+
imagegif($im);
17+
echo decbin(ord(ob_get_clean()[0xA]));
18+
?>
19+
--EXPECT--
20+
10110011

0 commit comments

Comments
 (0)