]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/v210dec.c
atrac3: switch to av_assert
[ffmpeg] / libavcodec / v210dec.c
index 1af7f943e13107a69999bd32113823f749e0d615..453390322d8e2df4c69cdc1cb5ea0a4fba9a5802 100644 (file)
@@ -58,6 +58,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
     avctx->bits_per_raw_sample = 10;
 
     avctx->coded_frame         = avcodec_alloc_frame();
+    if (!avctx->coded_frame)
+        return AVERROR(ENOMEM);
 
     s->unpack_frame            = v210_planar_unpack_c;
 
@@ -84,6 +86,18 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         stride = aligned_width * 8 / 3;
     }
 
+    if (avpkt->size < stride * avctx->height) {
+        if ((((avctx->width + 23) / 24) * 24 * 8) / 3 * avctx->height == avpkt->size) {
+            stride = avpkt->size / avctx->height;
+            if (!s->stride_warning_shown)
+                av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (64 byte) detected\n");
+            s->stride_warning_shown = 1;
+        } else {
+            av_log(avctx, AV_LOG_ERROR, "packet too small\n");
+            return -1;
+        }
+    }
+
     aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf);
     if (aligned_input != s->aligned_input) {
         s->aligned_input = aligned_input;
@@ -94,11 +108,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     if (pic->data[0])
         avctx->release_buffer(avctx, pic);
 
-    if (avpkt->size < stride * avctx->height) {
-        av_log(avctx, AV_LOG_ERROR, "packet too small\n");
-        return -1;
-    }
-
     pic->reference = 0;
     if (avctx->get_buffer(avctx, pic) < 0)
         return -1;
@@ -181,6 +190,6 @@ AVCodec ff_v210_decoder = {
     .close          = decode_close,
     .decode         = decode_frame,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
+    .long_name      = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
     .priv_class     = &v210dec_class,
 };