Browse Source

libobs: Fix potential crash when transitioning

Sometimes the A and B sources of a transition would a large difference
in their timestamps, and the calculation of where to start the audio
data for one of the sources could be above the tick size, which could
cause a crash.
jp9000 9 years ago
parent
commit
e93aeaef31
1 changed files with 4 additions and 2 deletions
  1. 4 2
      libobs/obs-source-transition.c

+ 4 - 2
libobs/obs-source-transition.c

@@ -738,6 +738,10 @@ static void process_audio(obs_source_t *transition, obs_source_t *child,
 
 	ts = child->audio_ts;
 	obs_source_get_audio_mix(child, &child_audio);
+	pos = (size_t)ns_to_audio_frames(sample_rate, ts - min_ts);
+
+	if (pos > AUDIO_OUTPUT_FRAMES)
+		return;
 
 	for (size_t mix_idx = 0; mix_idx < MAX_AUDIO_MIXES; mix_idx++) {
 		struct audio_output_data *output = &audio->output[mix_idx];
@@ -746,8 +750,6 @@ static void process_audio(obs_source_t *transition, obs_source_t *child,
 		if ((mixers & (1 << mix_idx)) == 0)
 			continue;
 
-		pos = (size_t)ns_to_audio_frames(sample_rate, ts - min_ts);
-
 		for (size_t ch = 0; ch < channels; ch++) {
 			float *out = output->data[ch];
 			float *in = input->data[ch];