]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mvha.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / mvha.c
index 4b03a79283586e1cafa0405ee2e8fabfbd28467e..4048e4625cb85324eecac6f9adbc331631ca02fa 100644 (file)
@@ -161,6 +161,9 @@ static int decode_frame(AVCodecContext *avctx,
     type = AV_RB32(avpkt->data);
     size = AV_RL32(avpkt->data + 4);
 
+    if (size < 1 || size >= avpkt->size)
+        return AVERROR_INVALIDDATA;
+
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
@@ -203,6 +206,9 @@ static int decode_frame(AVCodecContext *avctx,
         for (int i = 0; i < s->nb_symbols; symbol++) {
             int prob;
 
+            if (get_bits_left(gb) < 4)
+                return AVERROR_INVALIDDATA;
+
             if (get_bits1(gb)) {
                 prob = get_bits(gb, 12);
             } else {
@@ -227,6 +233,8 @@ static int decode_frame(AVCodecContext *avctx,
 
             dst = frame->data[p] + (avctx->height - 1) * frame->linesize[p];
             for (int y = 0; y < avctx->height; y++) {
+                if (get_bits_left(gb) < width)
+                    return AVERROR_INVALIDDATA;
                 for (int x = 0; x < width; x++) {
                     int v = get_vlc2(gb, s->vlc.table, s->vlc.bits, 3);
 
@@ -250,12 +258,14 @@ static int decode_frame(AVCodecContext *avctx,
 
         dst = frame->data[p] + (avctx->height - 1) * frame->linesize[p];
         s->llviddsp.add_left_pred(dst, dst, width, 0);
-        dst -= stride;
-        lefttop = left = dst[0];
-        for (int y = 1; y < avctx->height; y++) {
-            s->llviddsp.add_median_pred(dst, dst + stride, dst, width, &left, &lefttop);
-            lefttop = left = dst[0];
+        if (avctx->height > 1) {
             dst -= stride;
+            lefttop = left = dst[0];
+            for (int y = 1; y < avctx->height; y++) {
+                s->llviddsp.add_median_pred(dst, dst + stride, dst, width, &left, &lefttop);
+                lefttop = left = dst[0];
+                dst -= stride;
+            }
         }
     }
 
@@ -297,7 +307,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_mvha_decoder = {
+const AVCodec ff_mvha_decoder = {
     .name             = "mvha",
     .long_name        = NULL_IF_CONFIG_SMALL("MidiVid Archive Codec"),
     .type             = AVMEDIA_TYPE_VIDEO,