From 763c387149f7b189eff5b249155858a512ac76cd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 11 Oct 2017 02:33:55 -0400 Subject: [PATCH] audio: clamp resampler interpolation values to prevent buffer overflow. Partially fixes Bugzilla #3848. --- src/audio/SDL_audiocvt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index 3fb2aad9b69da..4808e672947e8 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -501,10 +501,9 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate, const int srcindex = (int) (outtime * inrate); const float intime = ((float) srcindex) / finrate; const float innexttime = ((float) (srcindex + 1)) / finrate; - - const float interpolation1 = 1.0f - (innexttime - outtime) / (innexttime - intime); + const float interpolation1 = SDL_max(0.0f, 1.0f - (innexttime - outtime) / (innexttime - intime)); const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING); - const float interpolation2 = 1.0f - interpolation1; + const float interpolation2 = SDL_max(0.0f, 1.0f - interpolation1); const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING); for (chan = 0; chan < chans; chan++) {