From d8203d3169b6d2f11313ab6ec6b471e01fac7974 Mon Sep 17 00:00:00 2001
From: Wohlstand <[EMAIL REDACTED]>
Date: Wed, 30 Aug 2023 08:36:31 +0300
Subject: [PATCH] music_wav.c: Fixed ADPCM buffer overflow
I accidentally found that the output buffer was been created for mono output only, and therefore, on attempt to play stereo files, the buffer overflow gets occured. So, the size of the buffer must be multipled by a number of channels.
Fixes #550
---
src/codecs/music_wav.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/codecs/music_wav.c b/src/codecs/music_wav.c
index 768b379d..f464ddcc 100644
--- a/src/codecs/music_wav.c
+++ b/src/codecs/music_wav.c
@@ -561,7 +561,7 @@ static int MS_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Uin
state->output.read = 0;
state->output.pos = 0;
- state->output.size = state->samplesperblock;
+ state->output.size = state->samplesperblock * state->channels;
state->output.data = (Sint16 *)SDL_malloc(state->output.size * sizeof(Sint16));
if (!state->output.data) {
return Mix_OutOfMemory();
@@ -791,7 +791,7 @@ static int IMA_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Ui
state->output.read = 0;
state->output.pos = 0;
- state->output.size = state->samplesperblock;
+ state->output.size = state->samplesperblock * state->channels;
state->output.data = (Sint16 *)SDL_malloc(state->output.size * sizeof(Sint16));
if (!state->output.data) {
return Mix_OutOfMemory();