Vulnerability: libavcodec/jpeg2000dec.c in FFmpeg before 2.1 does not ensure the use of valid code-block dimension values, which allows remote attackers to cause a denial of service (out-of-bounds array access) or possibly have unspecified other impact via crafted JPEG2000 data.
Vulnerability ID: CVE-2013-7018
CWE: CWE-119
Severity score: 6.4
Project: https://github.com/FFmpeg/FFmpeg
Published: 2013-12-09
File: libavcodec/jpeg2000dec.c
Commit message: jpeg2000: check log2_cblk dimensions

Fixes out of array access
Fixes Ticket2895

Found-by: Piotr Bandurski <ami_stuff@o2.pl>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Commit author: Michael Niedermayer

Vulnerable version (before fix):
 static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)         return AVERROR_INVALIDDATA;     }      c->cblk_style = bytestream2_get_byteu(&s->g);     if (c->cblk_style != 0) { // cblk style         av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style); static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,     int bpass_csty_symbol           = codsty->cblk_style & JPEG2000_CBLK_BYPASS;     int vert_causal_ctx_csty_symbol = codsty->cblk_style & JPEG2000_CBLK_VSC;      for (y = 0; y < height; y++)         memset(t1->data[y], 0, width * sizeof(**t1->data)); 

Fixed version (after fix):
 static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)         return AVERROR_INVALIDDATA;     }      if (c->log2_cblk_width > 6 || c->log2_cblk_height > 6) {         avpriv_request_sample(s->avctx, "cblk size > 64");         return AVERROR_PATCHWELCOME;     }      c->cblk_style = bytestream2_get_byteu(&s->g);     if (c->cblk_style != 0) { // cblk style         av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style); static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,     int bpass_csty_symbol           = codsty->cblk_style & JPEG2000_CBLK_BYPASS;     int vert_causal_ctx_csty_symbol = codsty->cblk_style & JPEG2000_CBLK_VSC;      av_assert0(width  <= JPEG2000_MAX_CBLKW);     av_assert0(height <= JPEG2000_MAX_CBLKH);      for (y = 0; y < height; y++)         memset(t1->data[y], 0, width * sizeof(**t1->data)); 

Patch:
patch: @@ -384,6 +384,11 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
         return AVERROR_INVALIDDATA;
     }
 
+    if (c->log2_cblk_width > 6 || c->log2_cblk_height > 6) {
+        avpriv_request_sample(s->avctx, "cblk size > 64");
+        return AVERROR_PATCHWELCOME;
+    }
+
     c->cblk_style = bytestream2_get_byteu(&s->g);
     if (c->cblk_style != 0) { // cblk style
         av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
@@ -1025,6 +1030,9 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
     int bpass_csty_symbol           = codsty->cblk_style & JPEG2000_CBLK_BYPASS;
     int vert_causal_ctx_csty_symbol = codsty->cblk_style & JPEG2000_CBLK_VSC;
 
+    av_assert0(width  <= JPEG2000_MAX_CBLKW);
+    av_assert0(height <= JPEG2000_MAX_CBLKH);
+
     for (y = 0; y < height; y++)
         memset(t1->data[y], 0, width * sizeof(**t1->data));
path: libavcodec/jpeg2000dec.c