-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Regression in SDL_ConvertAudio causing segmentation fault #6391
Comments
I'll check; I've got some weird buzzing in sdl12-compat in some cases too, and it would be nice if reverting this optimization fixes all this, honestly (the real win was moving from double to float, anyhow). |
Yes, I'm currently investigating some weird crashes too (SDL 2.24.0 on Windows) like this:
and I have call stacks that indicate that crashes are happening inside the This happens sometimes when the audio file with rate 22050 was loaded and SDL attempts to resample it to the rate 48000. P.S. What bothers me a bit here: with for (j = 0; (filterindex2 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)) < RESAMPLER_FILTER_SIZE; j++) {
const int jsamples = j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING;
const int srcframe = srcindex + 1 + j;
/* !!! FIXME: we can bubble this conditional out of here by doing a post loop. */
const float insample = (srcframe >= inframes) ? rpadding[((srcframe - inframes) * chans) + chan] : inbuf[(srcframe * chans) + chan];
|
I can confirm it's reading outside the bounds of From GDB:
|
So after a lot of agonizing, the fix is stupider than anticipated. :) Basically we have a variable that does, once per iteration of the loop: floatvalue += increment; And with a double this works out because there's enough precision for this to not mess up, but on a float, the precision errors accumulate, so this continues to drift more for each iteration, eventually blowing up when there's a large enough buffer for these errors to pile up enough to cause us to overflow a buffer. But there's no reason to accumulate errors, just multiply it by the loop counter each time instead: floatvalue = increment * i; This definitely fixes the test case in this bug, and likely other resampler bug reports. Valgrind shows no buffer overflows. |
I guess that should go into the 2.24.x branch too? |
I'm hoping we're finishing 2.26.0 soon, but just in case, it should go in 2.24.x. |
Done. |
I believe I've found a regression unless I'm just messing something silly up in how I'm calling SDL_ConvertAudio. I used git bisect and found that commit 111c3ad is where it broke.
I found the bug where I was doing conversion of real audio but was able to reproduce it in the following sample code with just a zero'd out audio buffer. cvt.len appears to be the culprit here. The number I used (16227964) happened to be the size of the real audio data I was working with. Replacing that with 20000000 works (no segfault).
In summary, the code below gives a segmentation fault. gdb shows it's coming from the function
SDL_ResampleAudio
(called fromSDL_ConvertAudio
. Before commit 111c3ad it works, afterwards it does not.Operating System is Arch Linux if that matters.
The text was updated successfully, but these errors were encountered: