1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-14 14:41:11 +02:00

Fix for unsage alloca usage (CWE-770)

Removed two looping usages of `alloca` that could lead to smashed stacks.

Signed-off-by: Emily Mabrey <emabrey@tenacityaudio.org>
This commit is contained in:
Emily Mabrey
2021-07-30 00:48:23 -04:00
parent f4c288e20b
commit 5854538e9a
2 changed files with 20 additions and 10 deletions

View File

@@ -3844,12 +3844,13 @@ bool AudioIoCallback::FillOutputBuffers(
// ------ MEMORY ALLOCATION ---------------------- // ------ MEMORY ALLOCATION ----------------------
// These are small structures. // These are small structures.
WaveTrack **chans = (WaveTrack **) alloca(numPlaybackChannels * sizeof(WaveTrack *)); auto chans = new WaveTrack * [numPlaybackChannels];
float **tempBufs = (float **) alloca(numPlaybackChannels * sizeof(float *)); auto tempBufs = new float* [numPlaybackChannels];
// And these are larger structures.... // And these are larger structures....
for (unsigned int c = 0; c < numPlaybackChannels; c++) for (unsigned int c = 0; c < numPlaybackChannels; c++) {
tempBufs[c] = (float *) alloca(framesPerBuffer * sizeof(float)); tempBufs[c] = new float[framesPerBuffer];
}
// ------ End of MEMORY ALLOCATION --------------- // ------ End of MEMORY ALLOCATION ---------------
auto & em = RealtimeEffectManager::Get(); auto & em = RealtimeEffectManager::Get();
@@ -4001,6 +4002,8 @@ bool AudioIoCallback::FillOutputBuffers(
if (outputMeterFloats != outputFloats) if (outputMeterFloats != outputFloats)
ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels ); ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels );
delete[] chans;
delete[] tempBufs;
return false; return false;
} }

View File

@@ -323,15 +323,15 @@ size_t RealtimeEffectManager::RealtimeProcess(int group, unsigned chans, float *
wxMilliClock_t start = wxGetUTCTimeMillis(); wxMilliClock_t start = wxGetUTCTimeMillis();
// Allocate the in/out buffer arrays // Allocate the in/out buffer arrays
float **ibuf = (float **) alloca(chans * sizeof(float *)); auto ibuf = new float* [chans];
float **obuf = (float **) alloca(chans * sizeof(float *)); auto obuf = new float* [chans];
// And populate the input with the buffers we've been given while allocating // And populate the input with the buffers we've been given while allocating
// NEW output buffers // NEW output buffers
for (unsigned int i = 0; i < chans; i++) for (unsigned int i = 0; i < chans; i++)
{ {
ibuf[i] = buffers[i]; ibuf[i] = buffers[i];
obuf[i] = (float *) alloca(numSamples * sizeof(float)); obuf[i] = new float[numSamples];
} }
// Now call each effect in the chain while swapping buffer pointers to feed the // Now call each effect in the chain while swapping buffer pointers to feed the
@@ -366,6 +366,9 @@ size_t RealtimeEffectManager::RealtimeProcess(int group, unsigned chans, float *
} }
} }
delete ibuf;
delete[] obuf;
// Remember the latency // Remember the latency
mRealtimeLatency = (int) (wxGetUTCTimeMillis() - start).GetValue(); mRealtimeLatency = (int) (wxGetUTCTimeMillis() - start).GetValue();
@@ -516,9 +519,10 @@ size_t RealtimeEffectState::RealtimeProcess(int group,
const auto numAudioIn = mEffect.GetAudioInCount(); const auto numAudioIn = mEffect.GetAudioInCount();
const auto numAudioOut = mEffect.GetAudioOutCount(); const auto numAudioOut = mEffect.GetAudioOutCount();
float **clientIn = (float **) alloca(numAudioIn * sizeof(float *)); auto clientIn = new float* [numAudioIn];
float **clientOut = (float **) alloca(numAudioOut * sizeof(float *)); auto clientOut = new float* [numAudioOut];
float *dummybuf = (float *) alloca(numSamples * sizeof(float)); auto dummybuf = new float [numSamples];
decltype(numSamples) len = 0; decltype(numSamples) len = 0;
auto ichans = chans; auto ichans = chans;
auto ochans = chans; auto ochans = chans;
@@ -613,6 +617,9 @@ size_t RealtimeEffectState::RealtimeProcess(int group,
// Bump to next processor // Bump to next processor
processor++; processor++;
} }
delete[] clientIn;
delete[] clientOut;
delete[] dummybuf;
return len; return len;
} }