libspeexdec: handle NULL return value from speex_packet_to_header()
authorJustin Ruggles <justin.ruggles@gmail.com>
Wed, 3 Oct 2012 21:26:16 +0000 (17:26 -0400)
committerJustin Ruggles <justin.ruggles@gmail.com>
Wed, 3 Oct 2012 22:26:25 +0000 (18:26 -0400)
This will happen when the extradata is not a valid Speex header.

libavcodec/libspeexdec.c

index 760bfe2..0c93f05 100644 (file)
@@ -40,12 +40,17 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
 {
     LibSpeexContext *s = avctx->priv_data;
     const SpeexMode *mode;
+    SpeexHeader *header = NULL;
     int spx_mode;
 
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
     if (avctx->extradata && avctx->extradata_size >= 80) {
-        SpeexHeader *header = speex_packet_to_header(avctx->extradata,
-                                                     avctx->extradata_size);
+        header = speex_packet_to_header(avctx->extradata,
+                                        avctx->extradata_size);
+        if (!header)
+            av_log(avctx, AV_LOG_WARNING, "Invalid Speex header\n");
+    }
+    if (header) {
         avctx->channels    = header->nb_channels;
         spx_mode           = header->mode;
         speex_header_free(header);