]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/scpr.c
vp9_metadata: Avoid allocations and copies of packet structures
[ffmpeg] / libavcodec / scpr.c
index cf511f83ccc8f4d1d9a25e7cb1d24e77adc58bf7..317950dafbf130e770d076428d9d4cde77a52f33 100644 (file)
@@ -359,7 +359,7 @@ static int decompress_i(AVCodecContext *avctx, uint32_t *dst, int linesize)
         ret = decode_run_i(avctx, ptype, run, &x, &y, clr,
                            dst, linesize, &lx, &ly,
                            backstep, off, &cx, &cx1);
-        if (run < 0)
+        if (ret < 0)
             return ret;
     }
 
@@ -372,7 +372,7 @@ static int decompress_p(AVCodecContext *avctx,
 {
     SCPRContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
-    int ret, temp, min, max, x, y, cx = 0, cx1 = 0;
+    int ret, temp = 0, min, max, x, y, cx = 0, cx1 = 0;
     int backstep = linesize - avctx->width;
 
     if (bytestream2_get_byte(gb) == 0)
@@ -382,8 +382,11 @@ static int decompress_p(AVCodecContext *avctx,
 
     ret  = decode_value(s, s->range_model, 256, 1, &min);
     ret |= decode_value(s, s->range_model, 256, 1, &temp);
+    if (ret < 0)
+        return ret;
+
     min += temp << 8;
-    ret |= decode_value(s, s->range_model, 256, 1, &max);
+    ret  = decode_value(s, s->range_model, 256, 1, &max);
     ret |= decode_value(s, s->range_model, 256, 1, &temp);
     if (ret < 0)
         return ret;
@@ -409,6 +412,10 @@ static int decompress_p(AVCodecContext *avctx,
         }
     }
 
+    ret = av_frame_copy(s->current_frame, s->last_frame);
+    if (ret < 0)
+        return ret;
+
     for (y = 0; y < s->nby; y++) {
         for (x = 0; x < s->nbx; x++) {
             int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
@@ -549,10 +556,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     } else if (type == 0 || type == 1) {
         frame->key_frame = 0;
 
-        ret = av_frame_copy(s->current_frame, s->last_frame);
-        if (ret < 0)
-            return ret;
-
         if (s->version == 1 || s->version == 2)
             ret = decompress_p(avctx, (uint32_t *)s->current_frame->data[0],
                                s->current_frame->linesize[0] / 4,
@@ -572,6 +575,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (ret < 0)
         return ret;
 
+    if (bytestream2_get_bytes_left(gb) > 5)
+        return AVERROR_INVALIDDATA;
+
     if (avctx->bits_per_coded_sample != 16) {
         ret = av_frame_ref(data, s->current_frame);
         if (ret < 0)