Fix memory corruption in AudioGeneratorAAC on non-ESP8266 platforms (#807)
The description of `AACDecode()` function states that the output buffer must be big enough for 1024 samples per channel _or_ 2048 if SBR is enabled. By default SBR is enabled on non-ESP8266 platforms, yet the buffer in `AudioGeneratorAAC` is always 1024 samples per channel long. This causes memory corruption on ESP32 and possibly Pi Pico. This change makes the output buffer correct.
This commit is contained in:
1 parent
70defdb6c6
commit
05f2fb0045
3 files changed
+11
-6
No files matched your search
@@ -31,7 +31,7 @@ AudioGeneratorAAC::AudioGeneratorAAC() {
|
||||
output = NULL;
|
||||
|
||||
buff = (uint8_t*)malloc(buffLen);
|
||||
outSample = (int16_t*)malloc(1024 * 2 * sizeof(uint16_t));
|
||||
outSample = (int16_t*)malloc(outSampleLen * sizeof(uint16_t));
|
||||
if (!buff || !outSample) {
|
||||
audioLogger->printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
Serial.flush();
|
||||
@@ -63,7 +63,7 @@ AudioGeneratorAAC::AudioGeneratorAAC(void *preallocateData, int preallocateSz) {
|
||||
buff = (uint8_t*) p;
|
||||
p += (buffLen + 7) & ~7;
|
||||
outSample = (int16_t*) p;
|
||||
p += (1024 * 2 * sizeof(int16_t) + 7) & ~7;
|
||||
p += (outSampleLen * sizeof(int16_t) + 7) & ~7;
|
||||
int used = p - (uint8_t*)preallocateSpace;
|
||||
int availSpace = preallocateSize - used;
|
||||
if (availSpace < 0) {
|
||||
@@ -212,7 +212,7 @@ bool AudioGeneratorAAC::begin(AudioFileSource *source, AudioOutput *output) {
|
||||
output->begin();
|
||||
|
||||
memset(buff, 0, buffLen);
|
||||
memset(outSample, 0, 1024 * 2 * sizeof(int16_t));
|
||||
memset(outSample, 0, outSampleLen * sizeof(int16_t));
|
||||
|
||||
|
||||
running = true;
|
||||
|
||||
Reference in new issue
Block a user