Bug 1325771 (CVE-2016-3977)

Summary: CVE-2016-3977 giflib: heap buffer overflow in gif2rgb
Product: [Other] Security Response Reporter: Andrej Nemec <anemec>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED WONTFIX QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: abaron, aortega, apevec, ayoung, chrisw, dallan, gkotton, gmollett, jaromir.capik, jschluet, lhh, lpeer, markmc, nmurray, rbryant, sclewis, slawomir, srevivo, tdecacqu, vgaikwad
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-05-04 02:23:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1325772    
Bug Blocks: 1325773    

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/.