Adds bounds checks to resampler to avoid OOB reads

Resampling would sometimes perform an OOB read into `inputBuffer` due it not containing enough data to calculate corresponding the output sample, this has been fixed by introducing bounds checking to ensure that the buffer has enough data.
This commit is contained in:
Billy Laws 2021-10-29 21:45:13 +05:30 committed by PixelyIon
parent 9e3b7a75b2
commit 6f59cba68d

View File

@ -137,10 +137,13 @@ namespace skyline::audio {
u32 lutIndex{fraction >> 8};
for (u8 channel{}; channel < channelCount; channel++) {
if (((inIndex + 3) * channelCount + channel) >= inputBuffer.size())
continue;
i32 data{inputBuffer[(inIndex + 0) * channelCount + channel] * lut[lutIndex].a +
inputBuffer[(inIndex + 1) * channelCount + channel] * lut[lutIndex].b +
inputBuffer[(inIndex + 2) * channelCount + channel] * lut[lutIndex].c +
inputBuffer[(inIndex + 3) * channelCount + channel] * lut[lutIndex].d};
inputBuffer[(inIndex + 1) * channelCount + channel] * lut[lutIndex].b +
inputBuffer[(inIndex + 2) * channelCount + channel] * lut[lutIndex].c +
inputBuffer[(inIndex + 3) * channelCount + channel] * lut[lutIndex].d};
outputBuffer[outIndex + channel] = Saturate<i16, i32>(data >> 15);
}