]> granicus.if.org Git - libjpeg-turbo/commitdiff
Fix int overflow when decompr. corrupt prog. JPEG
authorEven Rouault <even.rouault@spatialys.com>
Fri, 20 Jul 2018 16:04:15 +0000 (18:04 +0200)
committerDRC <information@libjpeg-turbo.org>
Tue, 24 Jul 2018 04:37:46 +0000 (23:37 -0500)
No discernible performance regression

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=9447
Credit to OSS Fuzz
Closes #259

ChangeLog.md
jdphuff.c

index 9300f3a887af4c8b1e358248041d33462d3fd745..27043fce74f575bcdc00d2a02834e1a7ecb76259 100644 (file)
@@ -52,6 +52,12 @@ a specially-crafted malformed color-index (8-bit-per-sample) BMP file in which
 some of the samples (color indices) exceeded the bounds of the BMP file's color
 table.
 
+9. Fixed a signed integer overflow in the progressive Huffman decoder, detected
+by the Clang and GCC undefined behavior sanitizers, that could be triggered by
+attempting to decompress a specially-crafted malformed JPEG image.  This issue
+did not pose a security threat, but removing the warning made it easier to
+detect actual security issues, should they arise in the future.
+
 
 1.5.3
 =====
index c927ffa071063cfe4efc948aea55e9054f90327f..06f0689024eb45b02d7b2d6dd4b0dee8422dde57 100644 (file)
--- a/jdphuff.c
+++ b/jdphuff.c
@@ -21,6 +21,7 @@
 #include "jinclude.h"
 #include "jpeglib.h"
 #include "jdhuff.h"             /* Declarations shared with jdhuff.c */
+#include <limits.h>
 
 
 #ifdef D_PROGRESSIVE_SUPPORTED
@@ -336,6 +337,10 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
       }
 
       /* Convert DC difference to actual value, update last_dc_val */
+      if ((state.last_dc_val[ci] >= 0 &&
+           s > INT_MAX - state.last_dc_val[ci]) ||
+          (state.last_dc_val[ci] < 0 && s < INT_MIN - state.last_dc_val[ci]))
+        ERREXIT(cinfo, JERR_BAD_DCT_COEF);
       s += state.last_dc_val[ci];
       state.last_dc_val[ci] = s;
       /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */