Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL audio write outside its allocated memory when resampling and segfault #201

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 1.2.11
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2006-08-09 13:29:27 +0000, Alfredo Tupone wrote:

When I open the audio specifying only the desired charatheristic, and not the obtained, number of samples can be changed inside the desired characteristic, if the driver is not able to comply with the request.
If it is going to use a different rate too, the number of sample user send is different from the one effectively sent to the driver

Just to point my case, I-m selecting "alsa + dmix", and it use 48000, while I asked for 11025.

The number of samples passed effectively to the driver are different that the one agreed (in my case about 4 times). I don't know if in that case the driver is behaving correctly, but however the behaviour is somewhat weird.
I think what should be done, if rate is different, is to get the number of samples desired from the user, multiply by the ratio between the rate, ask the driver, and report back the samples, scaled again, to the user

On 2006-08-17 11:40:39 +0000, Alfredo Tupone wrote:

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

On 2006-10-27 13:53:43 +0000, Alfredo Tupone wrote:

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 ) {
    

On 2006-10-27 15:46:59 +0000, Ryan C. Gordon wrote:

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.

On 2006-10-27 16:24:09 +0000, Ryan C. Gordon wrote:

Fixed in svn revision # 2878 for 1.2 branch, and svn revision # 2879 for 1.3 branch.

Thanks!

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant