We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2410 - Some audio channel count converters corrupt floating point audio and overflow buffer
Summary: Some audio channel count converters corrupt floating point audio and overflow...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.1
Hardware: All All
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-21 18:02 UTC by James Legg
Modified: 2014-02-22 23:29 UTC (History)
0 users

See Also:


Attachments
patch (4.22 KB, text/plain)
2014-02-21 18:02 UTC, James Legg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Legg 2014-02-21 18:02:57 UTC
Created attachment 1570 [details]
patch

For some channel count on floating point audio, SDL_ConvertAudio will corrupt the audio. In some cases it overflows the audio buffer as well.

In src/audio/SDL_audiocvt.c, functions SDL_ConvertMono, SDL_ConvertSurround, and SDL_ConvertSurround_4, treat the input as a 32 bit signed integer when the converter was set up to change the channel count of floating point audio. They each contain a switch statement that checks the format with the SDL_AUDIO_MASK_DATATYPE bit masked out, so the AUDIO_F32 case provided in SDL_ConvertMono and SDL_ConvertSurround is unreachable dead code.

SDL_ConvertSurround_4 doesn't have a separate float case, but it needs one as it does arithmetic on the values in the audio buffer.

There are pointer arithmetic errors in SDL_ConvertSurround causing buffer overflows on the converted audio buffer when using 4 byte formats (the AUDIO_S32 and unreachable AUDIO_F32 cases of the switch statement). Both the src and dst pointers use the wrong location. The output is written at a location which can be beyond the allocated size of the buffer through dst.

I've attached a patch which might fix these errors (I haven't tested all combinations, but the case I was using that caused me to find this bug sounds less painful with the patch applied).
Comment 1 Sam Lantinga 2014-02-22 23:29:58 UTC
Looks good, thanks!
https://hg.libsdl.org/SDL/rev/cc1d377f014a