]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/wavpack.c
dvbsubdec: check memory allocations and propagate errors
[ffmpeg] / libavcodec / wavpack.c
index 9c766ca181197271f2e2be91ae6789023d52d4be..cbc5b04d1ae3c3d1d47c601f350890c41abb0cd9 100644 (file)
@@ -699,9 +699,11 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb,
     } while (!last && count < s->samples);
 
     wv_reset_saved_context(s);
-    if ((s->avctx->err_recognition & AV_EF_CRCCHECK) &&
-        wv_check_crc(s, crc, crc_extra_bits))
-        return AVERROR_INVALIDDATA;
+    if (s->avctx->err_recognition & AV_EF_CRCCHECK) {
+        int ret = wv_check_crc(s, crc, crc_extra_bits);
+        if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
+            return ret;
+    }
 
     return 0;
 }
@@ -1120,6 +1122,11 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
         }
     }
 
+    if (wc->ch_offset + s->stereo >= avctx->channels) {
+        av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
+        return (avctx->err_recognition & AV_EF_EXPLODE) ? AVERROR_INVALIDDATA : 0;
+    }
+
     samples_l = frame->extended_data[wc->ch_offset];
     if (s->stereo)
         samples_r = frame->extended_data[wc->ch_offset + 1];
@@ -1207,6 +1214,11 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
         buf_size -= frame_size;
     }
 
+    if (s->ch_offset != avctx->channels) {
+        av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     *got_frame_ptr = 1;
 
     return avpkt->size;
@@ -1214,6 +1226,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
 
 AVCodec ff_wavpack_decoder = {
     .name           = "wavpack",
+    .long_name      = NULL_IF_CONFIG_SMALL("WavPack"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_WAVPACK,
     .priv_data_size = sizeof(WavpackContext),
@@ -1222,5 +1235,4 @@ AVCodec ff_wavpack_decoder = {
     .decode         = wavpack_decode_frame,
     .flush          = wavpack_decode_flush,
     .capabilities   = CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("WavPack"),
 };