From c388558d317f6bf8718ec3d22f4bf3540109dfe3 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 10 Feb 2012 18:51:57 +0000 Subject: wavpack: allow user to disable CRC checking Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavcodec/wavpack.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'libavcodec/wavpack.c') diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 1098873d7c..31604f51fc 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -500,6 +500,21 @@ static void wv_reset_saved_context(WavpackFrameContext *s) s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; } +static inline int wv_check_crc(WavpackFrameContext *s, uint32_t crc, + uint32_t crc_extra_bits) +{ + if (crc != s->CRC) { + av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); + return AVERROR_INVALIDDATA; + } + if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { + av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); + return AVERROR_INVALIDDATA; + } + + return 0; +} + static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) { @@ -610,14 +625,9 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, } while (!last && count < s->samples); wv_reset_saved_context(s); - if (crc != s->CRC) { - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; - } + if ((s->avctx->err_recognition & AV_EF_CRCCHECK) && + wv_check_crc(s, crc, crc_extra_bits)) + return AVERROR_INVALIDDATA; return count * 2; } @@ -680,14 +690,9 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, } while (!last && count < s->samples); wv_reset_saved_context(s); - if (crc != s->CRC) { - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; - } + if ((s->avctx->err_recognition & AV_EF_CRCCHECK) && + wv_check_crc(s, crc, crc_extra_bits)) + return AVERROR_INVALIDDATA; return count; } -- cgit v1.2.3