Mon, 09 Jan 2012 07:06:36 -0500Fixed structure alignment mismatch between Visual Studio and gcc on 64-bit architectures. SDL-1.2
Sam Lantinga [Mon, 09 Jan 2012 07:06:36 -0500] rev 6203
Fixed structure alignment mismatch between Visual Studio and gcc on 64-bit architectures.

Mon, 09 Jan 2012 04:53:58 -0500Don't hardcode output paths, Visual Studio does the right thing.
Sam Lantinga [Mon, 09 Jan 2012 04:53:58 -0500] rev 6202
Don't hardcode output paths, Visual Studio does the right thing.

Mon, 09 Jan 2012 04:39:55 -0500Removing test projects for Visual Studio 2005
Sam Lantinga [Mon, 09 Jan 2012 04:39:55 -0500] rev 6201
Removing test projects for Visual Studio 2005

Mon, 09 Jan 2012 04:38:34 -0500I can't test Visual Studio 2005 configurations anymore, and I don't think anyone is using it for production games.
Sam Lantinga [Mon, 09 Jan 2012 04:38:34 -0500] rev 6200
I can't test Visual Studio 2005 configurations anymore, and I don't think anyone is using it for production games.

Mon, 09 Jan 2012 04:36:57 -0500Fixed import library location SDL-1.2
Sam Lantinga [Mon, 09 Jan 2012 04:36:57 -0500] rev 6199
Fixed import library location

Mon, 09 Jan 2012 04:07:05 -0500Fixed output directories for win32/x64 platform output SDL-1.2
Sam Lantinga [Mon, 09 Jan 2012 04:07:05 -0500] rev 6198
Fixed output directories for win32/x64 platform output

Mon, 09 Jan 2012 00:24:08 -0500Futzing around with strip settings
Sam Lantinga [Mon, 09 Jan 2012 00:24:08 -0500] rev 6197
Futzing around with strip settings

Sun, 08 Jan 2012 17:31:11 -0500Fixed memory corruption in the upsampling code, caught by valgrind
Sam Lantinga [Sun, 08 Jan 2012 17:31:11 -0500] rev 6196
Fixed memory corruption in the upsampling code, caught by valgrind

Sun, 08 Jan 2012 17:20:33 -0500Fixed bug 1091 - Hardcoded size in SDL_audiocvt.c may lead to heap/stack corruption
Sam Lantinga [Sun, 08 Jan 2012 17:20:33 -0500] rev 6195
Fixed bug 1091 - Hardcoded size in SDL_audiocvt.c may lead to heap/stack corruption

Markovtsev Vadim 2011-01-18 22:00:16 PST

SDL_audiocvt.c:

static void SDLCALL
SDL_ConvertStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format):

#define dup_chans_1_to_2(type) \
{ \
const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \
for (i = cvt->len_cvt / 2; i; --i, --src) { \
const type val = *src; \
dst -= 2; \
dst[0] = dst[1] = val; \
} \
}

Pay attention to cvt->len_cvt / 2. 2 is the sizeof(Uint16), hovewer, below we
see that the conversion function supports Uint8 and Uint32:

switch (SDL_AUDIO_BITSIZE(format)) {
case 8:
dup_chans_1_to_2(Uint8);
break;
case 16:
dup_chans_1_to_2(Uint16);
break;
case 32:
dup_chans_1_to_2(Uint32);
break;
}

If type is Uint32, src will be decreased twice as it should be, memory being
written before the cvt->buf. If type is Uint8, the conversion will not be
complete. I suggest to change that define to

#define dup_chans_1_to_2(type) \
{ \
const type *src = (const type *) (cvt->buf + cvt->len_cvt); \
type *dst = (type *) (cvt->buf + cvt->len_cvt * 2); \
for (i = cvt->len_cvt / sizeof(type); i; --i, --src) { \
const type val = *src; \
dst -= 2; \
dst[0] = dst[1] = val; \
} \
}

I tested that and now it's working fine. I did not consider the similar defines
in functions nearby.

Sun, 08 Jan 2012 17:10:57 -0500Fixed bug 1014 - SDL_ConvertAudio crashes
Sam Lantinga [Sun, 08 Jan 2012 17:10:57 -0500] rev 6194
Fixed bug 1014 - SDL_ConvertAudio crashes

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.