Skip to content

Commit da7d839

Browse files
michaelnielenril
authored andcommitted
ffv1dec: check that global parameters do not change in version 0/1
Such changes are neither allowed nor supported Found-by: ami_stuff Bug-Id: CVE-2013-7020 CC: [email protected] Signed-off-by: Anton Khirnov <[email protected]>
1 parent 3187fa1 commit da7d839

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

libavcodec/ffv1dec.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ static int read_header(FFV1Context *f)
550550
memset(state, 128, sizeof(state));
551551

552552
if (f->version < 2) {
553+
int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample;
553554
unsigned v = get_symbol(c, state, 0);
554555
if (v > 1) {
555556
av_log(f->avctx, AV_LOG_ERROR,
@@ -566,15 +567,32 @@ static int read_header(FFV1Context *f)
566567
get_symbol(c, state, 1) + c->one_state[i];
567568
}
568569

569-
f->colorspace = get_symbol(c, state, 0); //YUV cs type
570+
colorspace = get_symbol(c, state, 0); //YUV cs type
571+
bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample;
572+
chroma_planes = get_rac(c, state);
573+
chroma_h_shift = get_symbol(c, state, 0);
574+
chroma_v_shift = get_symbol(c, state, 0);
575+
transparency = get_rac(c, state);
576+
577+
if (f->plane_count) {
578+
if (colorspace != f->colorspace ||
579+
bits_per_raw_sample != f->avctx->bits_per_raw_sample ||
580+
chroma_planes != f->chroma_planes ||
581+
chroma_h_shift != f->chroma_h_shift ||
582+
chroma_v_shift != f->chroma_v_shift ||
583+
transparency != f->transparency) {
584+
av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
585+
return AVERROR_INVALIDDATA;
586+
}
587+
}
570588

571-
if (f->version > 0)
572-
f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);
589+
f->colorspace = colorspace;
590+
f->avctx->bits_per_raw_sample = bits_per_raw_sample;
591+
f->chroma_planes = chroma_planes;
592+
f->chroma_h_shift = chroma_h_shift;
593+
f->chroma_v_shift = chroma_v_shift;
594+
f->transparency = transparency;
573595

574-
f->chroma_planes = get_rac(c, state);
575-
f->chroma_h_shift = get_symbol(c, state, 0);
576-
f->chroma_v_shift = get_symbol(c, state, 0);
577-
f->transparency = get_rac(c, state);
578596
f->plane_count = 2 + f->transparency;
579597
}
580598

0 commit comments

Comments
 (0)