cjpeg: Fix FPE when compressing 0-width GIF

Fixes #493
This commit is contained in:
DRC
2021-01-14 18:35:15 -06:00
parent 486cdcfb9d
commit 1719d12e51
3 changed files with 15 additions and 2 deletions

View File

@@ -15,6 +15,10 @@ block smoothing algorithm to read from uninitialized memory.
encoders to generate incorrect results when using the Clang compiler with encoders to generate incorrect results when using the Clang compiler with
Visual Studio. Visual Studio.
4. Fixed a floating point exception that occurred when attempting to compress a
specially-crafted malformed GIF image with a specified image width of 0 using
cjpeg.
2.0.90 (2.1 beta1) 2.0.90 (2.1 beta1)
================== ==================

View File

@@ -1,9 +1,11 @@
/* /*
* cderror.h * cderror.h
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009-2017 by Guido Vollbeding. * Modified 2009-2017 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * libjpeg-turbo Modifications:
* Copyright (C) 2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -60,6 +62,7 @@ JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
JMESSAGE(JERR_GIF_BUG, "GIF output got confused") JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d") JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB") JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
JMESSAGE(JERR_GIF_EMPTY, "Empty GIF image")
JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file") JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
JMESSAGE(JERR_GIF_NOT, "Not a GIF file") JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")

View File

@@ -1,9 +1,11 @@
/* /*
* rdgif.c * rdgif.c
* *
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2019 by Guido Vollbeding. * Modified 2019 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * libjpeg-turbo Modifications:
* Copyright (C) 2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg * For conditions of distribution and use, see the accompanying README.ijg
* file. * file.
* *
@@ -404,6 +406,8 @@ start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
ERREXIT(cinfo, JERR_INPUT_EOF); ERREXIT(cinfo, JERR_INPUT_EOF);
width = LM_to_uint(hdrbuf, 0); width = LM_to_uint(hdrbuf, 0);
height = LM_to_uint(hdrbuf, 2); height = LM_to_uint(hdrbuf, 2);
if (width == 0 || height == 0)
ERREXIT(cinfo, JERR_GIF_EMPTY);
/* we ignore the color resolution, sort flag, and background color index */ /* we ignore the color resolution, sort flag, and background color index */
aspectRatio = UCH(hdrbuf[6]); aspectRatio = UCH(hdrbuf[6]);
if (aspectRatio != 0 && aspectRatio != 49) if (aspectRatio != 0 && aspectRatio != 49)
@@ -446,6 +450,8 @@ start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* we ignore top/left position info, also sort flag */ /* we ignore top/left position info, also sort flag */
width = LM_to_uint(hdrbuf, 4); width = LM_to_uint(hdrbuf, 4);
height = LM_to_uint(hdrbuf, 6); height = LM_to_uint(hdrbuf, 6);
if (width == 0 || height == 0)
ERREXIT(cinfo, JERR_GIF_EMPTY);
source->is_interlaced = (BitSet(hdrbuf[8], INTERLACE) != 0); source->is_interlaced = (BitSet(hdrbuf[8], INTERLACE) != 0);
/* Read local colormap if header indicates it is present */ /* Read local colormap if header indicates it is present */