Преглед изворни кода

deps/media-playback: Check if frame can be played before using it

It's possible that frame_ready is false when this function is called,
which implies that the mp_decode frame field is not valid. However we
dereference the frame by counting the number of audio channels before
checking the value of frame_ready, causing a crash.
Richard Stanway пре 2 година
родитељ
комит
b9ef64d4eb
1 измењених фајлова са 4 додато и 3 уклоњено
  1. 4 3
      deps/media-playback/media-playback/media.c

+ 4 - 3
deps/media-playback/media-playback/media.c

@@ -356,15 +356,16 @@ void mp_media_next_audio(mp_media_t *m)
 	struct obs_source_audio audio = {0};
 	AVFrame *f = d->frame;
 	int channels;
+
+	if (!mp_media_can_play_frame(m, d))
+		return;
+
 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 19, 100)
 	channels = f->channels;
 #else
 	channels = f->ch_layout.nb_channels;
 #endif
 
-	if (!mp_media_can_play_frame(m, d))
-		return;
-
 	d->frame_ready = false;
 	if (!m->a_cb)
 		return;