comparison src/wma/wma.c @ 3053:a3734dd60d7a

Change the flow of codec probing to avoid the possibility of a null pointer dereference. From code analysis, unique IDs mPqomY & 8B8oHC.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 21:28:56 +0100
parents 13a0e4377c20
children 03f247c0d31d
comparison
equal deleted inserted replaced
3052:95b34f46a231 3053:a3734dd60d7a
163 av_register_all(); 163 av_register_all();
164 } 164 }
165 165
166 static int wma_is_our_fd(char *filename, VFSFile *fd) 166 static int wma_is_our_fd(char *filename, VFSFile *fd)
167 { 167 {
168 AVCodec *codec2; 168 AVCodec *codec2 = NULL;
169 AVCodecContext *c2 = NULL; 169 AVCodecContext *c2 = NULL;
170 AVFormatContext *ic2 = NULL; 170 AVFormatContext *ic2 = NULL;
171 int wma_idx2; 171 int wma_idx2;
172 172
173 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0; 173 if(av_open_input_vfsfile(&ic2, filename, fd, NULL, 0, NULL) < 0) return 0;
174 174
175 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) { 175 for(wma_idx2 = 0; wma_idx2 < ic2->nb_streams; wma_idx2++) {
176 c2 = &ic2->streams[wma_idx2]->codec; 176 c2 = &ic2->streams[wma_idx2]->codec;
177 if(c2->codec_type == CODEC_TYPE_AUDIO) break; 177 if(c2->codec_type == CODEC_TYPE_AUDIO)
178 {
179 av_find_stream_info(ic2);
180 codec2 = avcodec_find_decoder(c2->codec_id);
181 if (codec2) break;
182 }
178 } 183 }
184
185 if (!codec2) return 0;
179 186
180 av_find_stream_info(ic2); 187 av_find_stream_info(ic2);
181 188
182 codec2 = avcodec_find_decoder(c2->codec_id); 189 codec2 = avcodec_find_decoder(c2->codec_id);
183 190
298 playback->output->pause (0); 305 playback->output->pause (0);
299 } 306 }
300 307
301 static void wma_play_file(InputPlayback *playback) 308 static void wma_play_file(InputPlayback *playback)
302 { 309 {
303 AVCodec *codec; 310 AVCodec *codec = NULL;
304 AVCodecContext *c = NULL; 311 AVCodecContext *c = NULL;
305 AVFormatContext *ic = NULL; 312 AVFormatContext *ic = NULL;
306 uint8_t *inbuf_ptr; 313 uint8_t *inbuf_ptr;
307 int out_size, size, len; 314 int out_size, size, len;
308 AVPacket pkt; 315 AVPacket pkt;
311 318
312 if(av_open_input_file(&ic, playback->filename, NULL, 0, NULL) < 0) return; 319 if(av_open_input_file(&ic, playback->filename, NULL, 0, NULL) < 0) return;
313 320
314 for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) { 321 for(wma_idx = 0; wma_idx < ic->nb_streams; wma_idx++) {
315 c = &ic->streams[wma_idx]->codec; 322 c = &ic->streams[wma_idx]->codec;
316 if(c->codec_type == CODEC_TYPE_AUDIO) break; 323 if(c->codec_type == CODEC_TYPE_AUDIO)
324 {
325 av_find_stream_info(ic);
326 codec = avcodec_find_decoder(c->codec_id);
327 if (codec) break;
328 }
317 } 329 }
318 330
319 av_find_stream_info(ic); 331 if (!codec) return;
320
321 codec = avcodec_find_decoder(c->codec_id);
322
323 if(!codec) return;
324 332
325 if(avcodec_open(c, codec) < 0) return; 333 if(avcodec_open(c, codec) < 0) return;
326 334
327 wsong_title = get_song_title(ic, playback->filename); 335 wsong_title = get_song_title(ic, playback->filename);
328 wsong_time = get_song_time(ic); 336 wsong_time = get_song_time(ic);