audio: clamp resampler interpolation values to prevent buffer overflow.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 11 Oct 2017 02:33:55 -0400
changeset 11593b5e404b928ea
parent 11592 61260a51fc60
child 11594 61c151bcd76a
audio: clamp resampler interpolation values to prevent buffer overflow.

Partially fixes Bugzilla #3848.
src/audio/SDL_audiocvt.c
     1.1 --- a/src/audio/SDL_audiocvt.c	Wed Oct 11 02:31:58 2017 -0400
     1.2 +++ b/src/audio/SDL_audiocvt.c	Wed Oct 11 02:33:55 2017 -0400
     1.3 @@ -501,10 +501,9 @@
     1.4          const int srcindex = (int) (outtime * inrate);
     1.5          const float intime = ((float) srcindex) / finrate;
     1.6          const float innexttime = ((float) (srcindex + 1)) / finrate;
     1.7 -
     1.8 -        const float interpolation1 = 1.0f - (innexttime - outtime) / (innexttime - intime);
     1.9 +        const float interpolation1 = SDL_max(0.0f, 1.0f - (innexttime - outtime) / (innexttime - intime));
    1.10          const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
    1.11 -        const float interpolation2 = 1.0f - interpolation1;
    1.12 +        const float interpolation2 = SDL_max(0.0f, 1.0f - interpolation1);
    1.13          const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
    1.14  
    1.15          for (chan = 0; chan < chans; chan++) {