b=987679 update speex resampler to speexdsp d60e75b2 r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 07 Aug 2014 19:15:27 +1200
changeset 208483 b912d66f27d5324584d6c8cba18846f64b048d8a
parent 208482 c8657abef1d770f95c85e554d470fc908a3d4e3e
child 208484 e39901ab943017cda7dae1a02515236b2500d609
push idunknown
push userunknown
push dateunknown
reviewerspadenot
bugs987679
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=987679 update speex resampler to speexdsp d60e75b2 r=padenot
media/libspeex_resampler/README_MOZILLA
media/libspeex_resampler/hugemem.patch
media/libspeex_resampler/src/resample.c
--- a/media/libspeex_resampler/README_MOZILLA
+++ b/media/libspeex_resampler/README_MOZILLA
@@ -1,5 +1,5 @@
 This source is from the Speex DSP library
-(http://git.xiph.org/?p=speexdsp.git), from commit 769dc295.
+(http://git.xiph.org/?p=speexdsp.git), from commit d60e75b2.
 
 It consists in the audio resampling code (resampler.c) and its header files
 dependancies, imported into the tree using the update.sh script.
--- a/media/libspeex_resampler/hugemem.patch
+++ b/media/libspeex_resampler/hugemem.patch
@@ -15,29 +15,38 @@ diff --git a/media/libspeex_resampler/sr
  #ifdef OUTSIDE_SPEEX
  #include <stdlib.h>
  static void *speex_alloc (int size) {return calloc(size,1);}
  static void *speex_realloc (void *ptr, int size) {return realloc(ptr, size);}
  static void speex_free (void *ptr) {free(ptr);}
  #include "speex_resampler.h"
  #include "arch.h"
  #else /* OUTSIDE_SPEEX */
-@@ -632,18 +634,18 @@ static int update_filter(SpeexResamplerS
+@@ -633,24 +635,23 @@ static int update_filter(SpeexResamplerS
        if (st->oversample < 1)
           st->oversample = 1;
     } else {
        /* up-sampling */
        st->cutoff = quality_map[st->quality].upsample_bandwidth;
     }
     
     /* Choose the resampling type that requires the least amount of memory */
 -#ifdef RESAMPLE_FULL_SINC_TABLE
 -   use_direct = 1;
+-   if (INT_MAX/sizeof(spx_word16_t)/st->den_rate < st->filt_len)
+-      goto fail;
++   use_direct =
 +#ifdef RESAMPLE_HUGEMEM
-+   use_direct = st->den_rate <= 16*(st->oversample+8);
++     st->den_rate <= 16*(st->oversample+8)
  #else
-    use_direct = st->filt_len*st->den_rate <= st->filt_len*st->oversample+8;
- #endif
+-   use_direct = st->filt_len*st->den_rate <= st->filt_len*st->oversample+8
++     st->filt_len*st->den_rate <= st->filt_len*st->oversample+8
++#endif
+                 && INT_MAX/sizeof(spx_word16_t)/st->den_rate >= st->filt_len;
+-#endif
     if (use_direct)
     {
        min_sinc_table_length = st->filt_len*st->den_rate;
     } else {
+       if ((INT_MAX/sizeof(spx_word16_t)-8)/st->oversample < st->filt_len)
+          goto fail;
+ 
        min_sinc_table_length = st->filt_len*st->oversample+8;
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
@@ -74,16 +74,17 @@ static void speex_free (void *ptr) {free
 
 #include "speex/speex_resampler.h"
 #include "arch.h"
 #include "os_support.h"
 #endif /* OUTSIDE_SPEEX */
 
 #include "stack_alloc.h"
 #include <math.h>
+#include <limits.h>
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
 #ifdef FIXED_POINT
 #define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x)))  
 #else
@@ -634,25 +635,30 @@ static int update_filter(SpeexResamplerS
       if (st->oversample < 1)
          st->oversample = 1;
    } else {
       /* up-sampling */
       st->cutoff = quality_map[st->quality].upsample_bandwidth;
    }
    
    /* Choose the resampling type that requires the least amount of memory */
+   use_direct =
 #ifdef RESAMPLE_HUGEMEM
-   use_direct = st->den_rate <= 16*(st->oversample+8);
+     st->den_rate <= 16*(st->oversample+8)
 #else
-   use_direct = st->filt_len*st->den_rate <= st->filt_len*st->oversample+8;
+     st->filt_len*st->den_rate <= st->filt_len*st->oversample+8
 #endif
+                && INT_MAX/sizeof(spx_word16_t)/st->den_rate >= st->filt_len;
    if (use_direct)
    {
       min_sinc_table_length = st->filt_len*st->den_rate;
    } else {
+      if ((INT_MAX/sizeof(spx_word16_t)-8)/st->oversample < st->filt_len)
+         goto fail;
+
       min_sinc_table_length = st->filt_len*st->oversample+8;
    }
    if (st->sinc_table_length < min_sinc_table_length)
    {
       spx_word16_t *sinc_table = (spx_word16_t *)speex_realloc(st->sinc_table,min_sinc_table_length*sizeof(spx_word16_t));
       if (!sinc_table)
          goto fail;
 
@@ -689,26 +695,30 @@ static int update_filter(SpeexResamplerS
       if (st->quality>8)
          st->resampler_ptr = resampler_basic_interpolate_double;
       else
          st->resampler_ptr = resampler_basic_interpolate_single;
 #endif
       /*fprintf (stderr, "resampler uses interpolated sinc table and normalised cutoff %f\n", cutoff);*/
    }
 
-   
    /* Here's the place where we update the filter memory to take into account
       the change in filter length. It's probably the messiest part of the code
       due to handling of lots of corner cases. */
+
+   /* Adding buffer_size to filt_len won't overflow here because filt_len
+      could be multiplied by sizeof(spx_word16_t) above. */
    min_alloc_size = st->filt_len-1 + st->buffer_size;
    if (min_alloc_size > st->mem_alloc_size)
    {
-      spx_word16_t *mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*min_alloc_size * sizeof(spx_word16_t));
-      if (!mem)
-         goto fail;
+      spx_word16_t *mem;
+      if (INT_MAX/sizeof(spx_word16_t)/st->nb_channels < min_alloc_size)
+          goto fail;
+      else if (!(mem = (spx_word16_t*)speex_realloc(st->mem, st->nb_channels*min_alloc_size * sizeof(*mem))))
+          goto fail;
 
       st->mem = mem;
       st->mem_alloc_size = min_alloc_size;
    }
    if (!st->started)
    {
       spx_uint32_t i;
       for (i=0;i<st->nb_channels*st->mem_alloc_size;i++)