[libGD] #227 [Task opened] 8-bit animated GIFs broken due to VERY old bug

[email protected] Sun, 22 Aug 2010 05:30:57 +0200 (CEST)
Newsgroups php.gd.bugs
Message-ID <[email protected]>
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - Thomas Boutell (boutell) 

Attached to Project - libGD
Summary - 8-bit animated GIFs broken due to VERY old bug
Task Type - Bug Report
Category - Image Import/Export
Status - Unconfirmed
Assigned To - 
Operating System - All
Severity - High
Priority - Normal
Reported Version - 2.0.35
Due in Version - Undecided
Due Date - Undecided
Details - The following code in gd_gif_out.c is incorrect and has been incorrect probably since before I first borrowed it from Jef Poskanzer:

B |= (Resolution - 1) << 5;

Note that the leftmost bit of B is meant to be the global palette flag. When Resolution is 8 (which happens when images have 8-bit palettes), left-shifting 7 five places overwrites the leftmost bit, setting the global palette flag incorrectly.

This definitely breaks animated GIFs when the erroneous setting doesn't match what is desired - invalid GIFs are produced and rejected by browsers. It also sets the global colormap flag improperly for non-animated 256-color GIFs, however browsers seem to manage to tolerate this when the GIF has only one frame, otherwise the bug would have been reported sooner (as in, during the nineties (: ).

The specification says that the "original resolution" belongs one bit to the right of the colormap bit. So the correct code is:

B |= (Resolution - 1) << 4;

I made this fix and my animated GIF output worked well again.

(Comments in some places suggest that the resolution field is in fact useless but it does seem wise to set it to match the bits per pixel field.)

IMPORTANT: this appears twice in gd_gif_out.c. In GIFEncode, and also in gdImageGifAnimBeginCtx.

More information can be found at the following URL:
http://bugs.libgd.org/?do=details&task_id=227

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.