Signed-off-by: Paul B Mahol <[email protected]>
---
libavcodec/wavpack.c | 49 +++++++++++++++++++++++++++++--------------------
1 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 1098873..bcdbb20 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -408,7 +408,8 @@ static inline int wv_get_value_integer(WavpackFrameContext
*s, uint32_t *crc,
if (s->got_extra_bits && get_bits_left(&s->gb_extra_bits) >=
s->extra_bits) {
S |= get_bits(&s->gb_extra_bits, s->extra_bits);
- *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
+ if (s->avctx->err_recognition & AV_EF_CRCCHECK)
+ *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
}
}
@@ -488,7 +489,8 @@ static float wv_get_value_float(WavpackFrameContext *s,
uint32_t *crc, int S)
}
}
- *crc = *crc * 27 + S * 9 + exp * 3 + sign;
+ if (s->avctx->err_recognition & AV_EF_CRCCHECK)
+ *crc = *crc * 27 + S * 9 + exp * 3 + sign;
value.u = (sign << 31) | (exp << 23) | S;
return value.f;
@@ -500,6 +502,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)
{
@@ -591,7 +608,8 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s,
GetBitContext *gb,
pos = (pos + 1) & 7;
if (s->joint)
L += (R -= (L >> 1));
- crc = (crc * 3 + L) * 3 + R;
+ if (s->avctx->err_recognition & AV_EF_CRCCHECK)
+ crc = (crc * 3 + L) * 3 + R;
if (type == AV_SAMPLE_FMT_FLT) {
*dstfl++ = wv_get_value_float(s, &crc_extra_bits, L);
@@ -610,14 +628,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;
}
@@ -664,7 +677,8 @@ static inline int wv_unpack_mono(WavpackFrameContext *s,
GetBitContext *gb,
s->decorr[i].samplesA[j] = T = S;
}
pos = (pos + 1) & 7;
- crc = crc * 3 + S;
+ if (s->avctx->err_recognition & AV_EF_CRCCHECK)
+ crc = crc * 3 + S;
if (type == AV_SAMPLE_FMT_FLT) {
*dstfl = wv_get_value_float(s, &crc_extra_bits, S);
@@ -680,14 +694,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;
}
--
1.7.7
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel