Przeglądaj źródła

libobs: Fix null pointer access for video packets

Initialize arrays to 0, as otherwise these can get initialized with 
garbage data or potentially Visual Studio's default debug marker,
which is a problem if they're being checked against `NULL` later.
Ruwen Hahn 2 lat temu
rodzic
commit
9b5ce9fcec
1 zmienionych plików z 5 dodań i 4 usunięć
  1. 5 4
      libobs/obs-output.c

+ 5 - 4
libobs/obs-output.c

@@ -1829,9 +1829,9 @@ static bool get_audio_and_video_packets(struct obs_output *output,
 
 static bool initialize_interleaved_packets(struct obs_output *output)
 {
-	struct encoder_packet *video[MAX_OUTPUT_VIDEO_ENCODERS];
-	struct encoder_packet *audio[MAX_OUTPUT_AUDIO_ENCODERS];
-	struct encoder_packet *last_audio[MAX_OUTPUT_AUDIO_ENCODERS];
+	struct encoder_packet *video[MAX_OUTPUT_VIDEO_ENCODERS] = {0};
+	struct encoder_packet *audio[MAX_OUTPUT_AUDIO_ENCODERS] = {0};
+	struct encoder_packet *last_audio[MAX_OUTPUT_AUDIO_ENCODERS] = {0};
 	size_t start_idx;
 	size_t first_audio_idx;
 	size_t first_video_idx;
@@ -1896,7 +1896,8 @@ static bool initialize_interleaved_packets(struct obs_output *output)
 	output->highest_audio_ts -= audio[first_audio_idx]->dts_usec;
 
 	for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) {
-		output->highest_video_ts[i] -= video[i]->dts_usec;
+		if (video[i])
+			output->highest_video_ts[i] -= video[i]->dts_usec;
 	}
 
 	/* apply new offsets to all existing packet DTS/PTS values */