diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index 9aec2cc462..c9fd80b838 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -370,6 +370,13 @@ static av_cold int encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } + if (s->predictor == MEDIAN && s->version <= 2 && + (avctx->width < 4 || + AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift) < 2 + s->interlaced)) { + av_log(avctx, AV_LOG_ERROR, "Frame too small for the median predictor\n"); + return AVERROR(EINVAL); + } + avctx->extradata[0] = s->predictor | (s->decorrelate << 6); avctx->extradata[2] = s->interlaced ? 0x10 : 0x20; if (s->context)