X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fffv1dec.c;h=4349af571a5f9e64997b1209fecdd8810fd710b7;hb=72025ac36c740f031d7e413041fdfe97087c83c4;hp=8f7b2bf32e286271ff49d8c23e4f7848502c628c;hpb=fb0c9d41d685abb58575c5482ca33b8cd457c5ec;p=ffmpeg diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 8f7b2bf32e2..4349af571a5 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -328,6 +328,14 @@ static int decode_slice_header(FFV1Context *f, FFV1Context *fs) f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0); f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0); + if (av_image_check_sar(f->width, f->height, + f->cur->sample_aspect_ratio) < 0) { + av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", + f->cur->sample_aspect_ratio.num, + f->cur->sample_aspect_ratio.den); + f->cur->sample_aspect_ratio = (AVRational){ 0, 1 }; + } + return 0; } @@ -542,6 +550,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, colorspace, bits_per_raw_sample; unsigned v = get_symbol(c, state, 0); if (v > 1) { av_log(f->avctx, AV_LOG_ERROR, @@ -558,15 +567,32 @@ static int read_header(FFV1Context *f) get_symbol(c, state, 1) + c->one_state[i]; } - f->colorspace = get_symbol(c, state, 0); //YUV cs type + colorspace = get_symbol(c, state, 0); //YUV cs type + bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample; + 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 (colorspace != f->colorspace || + bits_per_raw_sample != f->avctx->bits_per_raw_sample || + 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; + } + } - if (f->version > 0) - f->avctx->bits_per_raw_sample = get_symbol(c, state, 0); + f->colorspace = colorspace; + f->avctx->bits_per_raw_sample = bits_per_raw_sample; + f->chroma_planes = chroma_planes; + f->chroma_h_shift = chroma_h_shift; + f->chroma_v_shift = chroma_v_shift; + f->transparency = transparency; - 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; } @@ -801,13 +827,13 @@ static av_cold int ffv1_decode_init(AVCodecContext *avctx) static int ffv1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; + uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FFV1Context *f = avctx->priv_data; RangeCoder *const c = &f->slice_context[0]->c; int i, ret; uint8_t keystate = 128; - const uint8_t *buf_p; + uint8_t *buf_p; AVFrame *const p = data; f->cur = p; @@ -869,7 +895,7 @@ static int ffv1_decode_frame(AVCodecContext *avctx, void *data, if (i) { ff_init_range_decoder(&fs->c, buf_p, v); } else - fs->c.bytestream_end = (uint8_t *)(buf_p + v); + fs->c.bytestream_end = buf_p + v; fs->cur = p; } @@ -893,7 +919,7 @@ static int ffv1_decode_frame(AVCodecContext *avctx, void *data, f->last_picture->linesize[j] * (fs->slice_y >> sv) + (fs->slice_x >> sh); } - av_image_copy(dst, p->linesize, (const uint8_t **)src, + av_image_copy(dst, p->linesize, src, f->last_picture->linesize, avctx->pix_fmt, fs->slice_width, fs->slice_height);