Bug 1325771 (CVE-2016-3977) - CVE-2016-3977 giflib: heap buffer overflow in gif2rgb
Summary: CVE-2016-3977 giflib: heap buffer overflow in gif2rgb
Keywords:
Status: CLOSED WONTFIX
Alias: CVE-2016-3977
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 1325772
Blocks: 1325773
TreeView+ depends on / blocked
 
Reported: 2016-04-11 07:35 UTC by Andrej Nemec
Modified: 2019-09-29 13:46 UTC (History)
20 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-05-04 02:23:31 UTC


Attachments (Terms of Use)

Description Andrej Nemec 2016-04-11 07:35:43 UTC
A heap buffer overflow vulnerability was found in giflib. A maliciously crafted gif file could cause the application to crash.

External references:

https://sourceforge.net/p/giflib/bugs/87/

Upstream fix:

https://sourceforge.net/p/giflib/code/ci/ea8dbc5786862a3e16a5acfa3d24e2c2f608cd88/

References:

http://bugs.fi/2016-03-gif2rgb.txt
http://bugs.fi/media/afl/giflib/1.gif

Comment 1 Andrej Nemec 2016-04-11 07:37:15 UTC
Created giflib tracking bugs for this issue:

Affects: fedora-all [bug 1325772]

Comment 2 Stefan Cornelius 2016-04-20 16:19:34 UTC
The palette of the image has only 2 colors, but the background color is set to an index value of 255, which, in this case, is outside the range of valid values.

The main() function sets the background image value when filling up the screen buffer:
(line numbers for RHEL7)
148     for (i = 0; i < GifFile->SWidth; i++)  /* Set its color to BackGround. */
149     ScreenBuffer[0][i] = GifFile->SBackGroundColor;


Later, in the DumpScreen2RGB function, it tries to look up the background color within the palette:
292             GifRow = ScreenBuffer[i];
    293             GifQprintf("\b\b\b\b%-4d", ScreenHeight - i);
    294             for (j = 0, BufferP = Buffer; j < ScreenWidth; j++) {
    295                 ColorMapEntry = &ColorMap->Colors[GifRow[j]];
    296                 *BufferP++ = ColorMapEntry->Red;
    297                 *BufferP++ = ColorMapEntry->Green;
    298                 *BufferP++ = ColorMapEntry->Blue;
    
GifRow[j] can be the background color index (255), which is not inside the limits of the ColorMap->Colors array.
Subsequent processing leads to out-of-bounds reads, but they should not be dangerous (worst case is a crash).

Additionally, as far as I can tell, the giflib library itself is not vulnerable to this attack, only the gif2rgb utility.

Comment 3 Stefan Cornelius 2016-04-20 16:21:18 UTC
Statement:

Red Hat Product Security has rated this issue as having Low security impact. This issue is not currently planned to be addressed in future updates. For additional information, refer to the Issue Severity Classification: https://access.redhat.com/security/updates/classification/.


Note You need to log in before you can comment on or make changes to this bug.