diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-03-16 02:32:36 +0300 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-03-16 02:32:36 +0300 |
commit | d92e9bd2bf9de0cf59f18b1ca9e565fcccaf3487 (patch) | |
tree | eee9f80bb2e5141cba634b8eec9249d4592099ca | |
parent | 4c7f0a5ffd7ea5e52968aad1e89108e124be012b (diff) |
Doing some sanity checking (just in case) on the propagated long-term
prediction
git-svn-id: http://svn.xiph.org/trunk/speex@12765 0101bb08-14d6-0310-b084-bc0e0c8e3800
-rw-r--r-- | libspeex/filters.c | 18 | ||||
-rw-r--r-- | libspeex/filters.h | 1 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 6 |
3 files changed, 24 insertions, 1 deletions
diff --git a/libspeex/filters.c b/libspeex/filters.c index d49d4d8..48b4753 100644 --- a/libspeex/filters.c +++ b/libspeex/filters.c @@ -62,6 +62,24 @@ void bw_lpc(spx_word16_t gamma, const spx_coef_t *lpc_in, spx_coef_t *lpc_out, i } } +void sanitize_values32(spx_word32_t *vec, spx_word32_t min_val, spx_word32_t max_val, int len) +{ + int i; + for (i=0;i<len;i++) + { + /* It's important we do the test that way so we can catch NaNs, which are neither greater nor smaller */ + if (!(vec[i]>=min_val && vec[i] <= max_val)) + { + if (vec[i] < min_val) + vec[i] = min_val; + else if (vec[i] > max_val) + vec[i] = max_val; + else /* Has to be NaN */ + vec[i] = 0; + } + } +} + void highpass(const spx_word16_t *x, spx_word16_t *y, int len, int filtID, spx_mem_t *mem) { int i; diff --git a/libspeex/filters.h b/libspeex/filters.h index fee68ab..b363a9a 100644 --- a/libspeex/filters.h +++ b/libspeex/filters.h @@ -67,6 +67,7 @@ void fir_mem16(const spx_word16_t *x, const spx_coef_t *num, spx_word16_t *y, in /* Apply bandwidth expansion on LPC coef */ void bw_lpc(spx_word16_t , const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order); +void sanitize_values32(spx_word32_t *vec, spx_word32_t min_val, spx_word32_t max_val, int len); void syn_percep_zero16(const spx_word16_t *xx, const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack); diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index 55bba6e..24b2044 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -1526,7 +1526,11 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) #ifdef EPIC_48K } #endif - + /* Ensuring that things aren't blowing up as would happen if e.g. an encoder is + crafting packets to make us produce NaNs and slow down the decoder (vague DoS threat). + We can probably be even more aggressive and limit to 15000 or so. */ + sanitize_values32(exc32, NEG32(QCONST32(32000,SIG_SHIFT-1)), QCONST32(32000,SIG_SHIFT-1), st->subframeSize); + tmp = gain_3tap_to_1tap(pitch_gain); pitch_average += tmp; |