• Sam Lantinga's avatar
    Fixed bug 1014 - SDL_ConvertAudio crashes · a9bcdb83
    Sam Lantinga authored
    The patch Mark attached looks good and valgrind gives it a clean bill of health:
    
    Mark.Howson@ntu.ac.uk 2010-12-15 07:45:25 PST
    
    Reproducible here under Windows and Linux. Looking at the code for
    SDL_Upsample_S16LSB_2c:
    
    const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
    Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
    const Sint16 *target = ((const Sint16 *) cvt->buf) - 2;
    while (dst > target) {
       dst[1] = ((Sint16) SDL_SwapLE16(sample1));
       dst[0] = ((Sint16) SDL_SwapLE16(sample0));
       dst -= 2;
    ...
    
    if dstsize is odd (and therefore dst), it'll write to target[1] which is one
    byte before the allocated buf.
    
    The attached patch to sdlgenaudiocvt.pl changes dst > target to dst >= target,
    and removes the - $channels for the upsample case. The patch is not fully
    tested, but seems to work here.
    a9bcdb83
Name
Last commit
Last update
..
alsa Loading commit data...
android Loading commit data...
arts Loading commit data...
baudio Loading commit data...
bsd Loading commit data...
coreaudio Loading commit data...
directsound Loading commit data...
disk Loading commit data...
dsp Loading commit data...
dummy Loading commit data...
esd Loading commit data...
fusionsound Loading commit data...
nas Loading commit data...
nds Loading commit data...
paudio Loading commit data...
pulseaudio Loading commit data...
qsa Loading commit data...
sun Loading commit data...
winmm Loading commit data...
xaudio2 Loading commit data...
SDL_audio.c Loading commit data...
SDL_audio_c.h Loading commit data...
SDL_audiocvt.c Loading commit data...
SDL_audiodev.c Loading commit data...
SDL_audiodev_c.h Loading commit data...
SDL_audiomem.h Loading commit data...
SDL_audiotypecvt.c Loading commit data...
SDL_mixer.c Loading commit data...
SDL_sysaudio.h Loading commit data...
SDL_wave.c Loading commit data...
SDL_wave.h Loading commit data...
sdlgenaudiocvt.pl Loading commit data...