| Summary: | SDL audio write outside its allocated memory when resampling and segfault | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Alfredo Tupone <alfredo> |
| Component: | audio | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Ryan C. Gordon <icculus> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 1.2.11 | ||
| Hardware: | All | ||
| OS: | All | ||
|
Description
Alfredo Tupone
2006-08-09 13:29:27 UTC
I have more information on that. As it was pointed out by valgrind, when SDL was asked to autonomally convert the incoming stream, it write outside its allocated buffer. A simple patch is to set audio->convert.len = desired->size / audio->convert.len_ratio; when preparing the conversion structures. This fixes the segfault, and sound is little better. I suppose this is not the only fix to apply, maybe someone should study what to do, or remove the auto-resampling facility if there is nothing to do to fix it Patch to fix this bug.
--- src/audio/SDL_audio.c.old 2006-10-19 08:16:18.000000000 +0200
+++ src/audio/SDL_audio.c 2006-10-19 08:18:08.000000000 +0200
@@ -591,7 +591,7 @@
return(-1);
}
if ( audio->convert.needed ) {
- audio->convert.len = desired->size;
+ audio->convert.len = desired->size / audio->convert.len_ratio;
audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
audio->convert.len*audio->convert.len_mult);
if ( audio->convert.buf == NULL ) {
Looking at this now. (Be aware that SDL 1.2 only does correct audio resampling when the source and destination are powers of two...so 11025->48000 will always sound a little wrong, but 11025->44100 will sound okay. We're fixing this for SDL 1.3.) --ryan. Fixed in svn revision #2878 for 1.2 branch, and svn revision #2879 for 1.3 branch. Thanks! --ryan. |