libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[SDL3, ADPCM] Running out of buffer at `state->output.data` buffer size at MS_ADPCM_DecodeBlockData

Wohlstand opened this issue · comments

Recently, I tried to make a small experiment with MS ADPCM thing, and I accidentally caught an AddressSanitizer's error at the MS_ADPCM_DecodeBlockData() call. Then, I added the assertion:

SDL_assert(outpos < state->output.size);

prior to the:

state->output.data[outpos++] = sample1;

and it fails:
Снимок экрана от 2023-08-30 07-42-13

I hadn't figured yet for the source of issue yet, but if I will find something, I'll make a pull-request. Otherewise, let me know if somebody make a fix before me.

P.S. The file that causes an error:
a_ja_tolko_s_moroza_[antonov_andrei]-adpcm_ms.wav.zip

I generated it via ffmpeg somewhere in 2018 for my local tests. It works just fine at other players such as VLC.

P.P.S. Also IMA ADPCM too:
a_ja_tolko_s_moroza_[antonov_andrei]-adpcm_ima_wav.wav.zip

Okay, I figured for the true source of a problem: the code doesn't care about multi-channel files, and buffere got been created for the mono streams only. So, I fixed the problem by multiplying a buffer size by an actual number of channels.