Vulnerability: The read_header function in libavcodec/ffv1dec.c in FFmpeg before 2.1 does not prevent changes to global parameters, which allows remote attackers to cause a denial of service (out-of-bounds array access) or possibly have unspecified other impact via crafted FFV1 data.
Vulnerability ID: CVE-2013-7011
CWE: CWE-119
Severity score: 6.4
Project: https://github.com/FFmpeg/FFmpeg
Published: 2013-12-09
File: libavcodec/ffv1dec.c
Commit message: ffv1dec: check that global parameters dont change in version 0/1

Such changes are not allowed nor supported

Fixes Ticket2906

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

Vulnerable version (before fix):
 static int read_header(FFV1Context *f)     memset(state, 128, sizeof(state));      if (f->version < 2) {         unsigned v= get_symbol(c, state, 0);         if (v >= 2) {             av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v); static int read_header(FFV1Context *f)         if (f->version > 0)             f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);          f->chroma_planes  = get_rac(c, state);         f->chroma_h_shift = get_symbol(c, state, 0);         f->chroma_v_shift = get_symbol(c, state, 0);         f->transparency   = get_rac(c, state);         f->plane_count    = 2 + f->transparency;     } 

Fixed version (after fix):
 static int read_header(FFV1Context *f)     memset(state, 128, sizeof(state));      if (f->version < 2) {         int chroma_planes, chroma_h_shift, chroma_v_shift, transparency;         unsigned v= get_symbol(c, state, 0);         if (v >= 2) {             av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v); static int read_header(FFV1Context *f)         if (f->version > 0)             f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);          chroma_planes  = get_rac(c, state);         chroma_h_shift = get_symbol(c, state, 0);         chroma_v_shift = get_symbol(c, state, 0);         transparency   = get_rac(c, state);          if (f->plane_count) {             if (   chroma_planes != f->chroma_planes                 || chroma_h_shift!= f->chroma_h_shift                 || chroma_v_shift!= f->chroma_v_shift                 || transparency  != f->transparency) {                 av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");                 return AVERROR_INVALIDDATA;             }         }          f->chroma_planes  = chroma_planes;         f->chroma_h_shift = chroma_h_shift;         f->chroma_v_shift = chroma_v_shift;         f->transparency   = transparency;          f->plane_count    = 2 + f->transparency;     } 

Patch:
patch: @@ -580,6 +580,7 @@ static int read_header(FFV1Context *f)
     memset(state, 128, sizeof(state));
 
     if (f->version < 2) {
+        int chroma_planes, chroma_h_shift, chroma_v_shift, transparency;
         unsigned v= get_symbol(c, state, 0);
         if (v >= 2) {
             av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v);
@@ -597,10 +598,26 @@ static int read_header(FFV1Context *f)
         if (f->version > 0)
             f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);
 
-        f->chroma_planes  = get_rac(c, state);
-        f->chroma_h_shift = get_symbol(c, state, 0);
-        f->chroma_v_shift = get_symbol(c, state, 0);
-        f->transparency   = get_rac(c, state);
+        chroma_planes  = get_rac(c, state);
+        chroma_h_shift = get_symbol(c, state, 0);
+        chroma_v_shift = get_symbol(c, state, 0);
+        transparency   = get_rac(c, state);
+
+        if (f->plane_count) {
+            if (   chroma_planes != f->chroma_planes
+                || chroma_h_shift!= f->chroma_h_shift
+                || chroma_v_shift!= f->chroma_v_shift
+                || transparency  != f->transparency) {
+                av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
+                return AVERROR_INVALIDDATA;
+            }
+        }
+
+        f->chroma_planes  = chroma_planes;
+        f->chroma_h_shift = chroma_h_shift;
+        f->chroma_v_shift = chroma_v_shift;
+        f->transparency   = transparency;
+
         f->plane_count    = 2 + f->transparency;
     }
path: libavcodec/ffv1dec.c