diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2018-03-23 03:16:33 -0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2018-03-23 12:23:21 -0400 |
commit | df5706a78dd68355c4c5128b412116592e4401fc (patch) | |
tree | 7d2a1a2be4aa0ff72486d579e04465ea947daf59 | |
parent | 32fb553eb4a800c5862bf34787cad26bc0e80e20 (diff) | |
download | opus-df5706a78dd68355c4c5128b412116592e4401fc.tar.gz |
Adding decoder state validation
-rw-r--r-- | celt/celt.h | 7 | ||||
-rw-r--r-- | celt/celt_decoder.c | 33 |
2 files changed, 40 insertions, 0 deletions
diff --git a/celt/celt.h b/celt/celt.h index ce8349cf..24b6b2b5 100644 --- a/celt/celt.h +++ b/celt/celt.h @@ -209,6 +209,13 @@ static OPUS_INLINE int fromOpus(unsigned char c) extern const signed char tf_select_table[4][8]; +#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) +void validate_celt_decoder(CELTDecoder *st); +#define VALIDATE_CELT_DECODER(st) validate_celt_decoder(st) +#else +#define VALIDATE_CELT_DECODER(st) +#endif + int resampling_factor(opus_int32 rate); void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c index 944b5e10..0d287607 100644 --- a/celt/celt_decoder.c +++ b/celt/celt_decoder.c @@ -101,6 +101,38 @@ struct OpusCustomDecoder { /* opus_val16 backgroundLogE[], Size = 2*mode->nbEBands */ }; +#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS) +/* Make basic checks on the CELT state to ensure we don't end + up writing all over memory. */ +void validate_celt_decoder(CELTDecoder *st) +{ +#ifndef CUSTOM_MODES + celt_assert(st->mode == opus_custom_mode_create(48000, 960, NULL)); + celt_assert(st->overlap == 120); +#endif + celt_assert(st->channels == 1 || st->channels == 2); + celt_assert(st->stream_channels == 1 || st->stream_channels == 2); + celt_assert(st->downsample > 0); + celt_assert(st->start == 0 || st->start == 17); + celt_assert(st->start < st->end); + celt_assert(st->end <= 21); +#ifdef OPUS_ARCHMASK + celt_assert(st->arch >= 0); + celt_assert(st->arch <= OPUS_ARCHMASK); +#endif + celt_assert(st->last_pitch_index <= MAX_PERIOD); + celt_assert(st->last_pitch_index >= 0); + celt_assert(st->postfilter_period <= MAX_PERIOD); + celt_assert(st->postfilter_period >= 0); + celt_assert(st->postfilter_period_old <= MAX_PERIOD); + celt_assert(st->postfilter_period_old >= 0); + celt_assert(st->postfilter_tapset <= 2); + celt_assert(st->postfilter_tapset >= 0); + celt_assert(st->postfilter_tapset_old <= 2); + celt_assert(st->postfilter_tapset_old >= 0); +} +#endif + int celt_decoder_get_size(int channels) { const CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); @@ -832,6 +864,7 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat const opus_int16 *eBands; ALLOC_STACK; + VALIDATE_CELT_DECODER(st); mode = st->mode; nbEBands = mode->nbEBands; overlap = mode->overlap; |