Skip to content

Commit 234ec03

Browse files
ivan-mogilkoicculus
authored andcommitted
Fix another infinite loop in mix_source_buffer(), case of uneven input
This fixes another potential infinite loop, which may occur if remaining data in the input is less than `bufferframesize`, in such case `framesavail` resulted in 0, and src->offset never advanced. There are seemingly two options here: 1. Skip the remainder. 2. Use a local temp buffer, copy the remainder over and fill necessary remaining bytes with zeroes, then pass it into mix_buffer() too. I chose the first, as this ever affects only 1 last sample which, apparently, does not have all of the channels data filled, so this does not seem to be worth it.
1 parent 864c4aa commit 234ec03

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

mojoal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,11 @@ static ALboolean mix_source_buffer(ALCcontext *ctx, ALsource *src, BufferQueueIt
14711471
const int mixframes = SDL_min(framesneeded, framesavail);
14721472
mix_buffer(src, buffer, src->panning, data, *stream, mixframes);
14731473
src->offset += mixframes * bufferframesize;
1474+
/* workaround in case remains are less than bufferframesize:
1475+
in this case it's easier to just skip the remaining sample */
1476+
if ((src->offset < buffer->len) && ((buffer->len - src->offset) < bufferframesize)) {
1477+
src->offset = buffer->len;
1478+
}
14741479
*len -= mixframes * deviceframesize;
14751480
*stream += mixframes * ctx->device->channels;
14761481
}

0 commit comments

Comments
 (0)