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

Fix potential infinite loop in mix_source_buffer() in case of uneven input buffer #31

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mojoal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,12 +1432,15 @@ static ALboolean mix_source_buffer(ALCcontext *ctx, ALsource *src, BufferQueueIt
if (src->stream) { /* resampling? */
int mixframes, mixlen, remainingmixframes;
while ( (((mixlen = SDL_AudioStreamAvailable(src->stream)) / bufferframesize) < framesneeded) && (src->offset < buffer->len) ) {
const int framesput = (buffer->len - src->offset) / bufferframesize;
const int bytesput = SDL_min(framesput, 1024) * bufferframesize;
const int bytesleft = (buffer->len - src->offset);
/* workaround in case remains are less than bufferframesize */
const int framesput = (bytesleft + (bufferframesize - 1)) / bufferframesize;
const int bytesput = SDL_min(SDL_min(framesput, 1024) * bufferframesize, bytesleft);
FIXME("dynamically adjust frames here?"); /* we hardcode 1024 samples when opening the audio device, too. */
SDL_AudioStreamPut(src->stream, data, bytesput);
src->offset += bytesput;
data += bytesput / sizeof (float);
/* workaround in case remains are not evenly divided by sizeof (float) */
data += (bytesput + (sizeof (float) - 1)) / sizeof (float);
}

mixframes = SDL_min(mixlen / bufferframesize, framesneeded);
Expand Down
Loading