probe_codec: fix memory corruption
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 25 Jul 2012 23:05:01 +0000 (01:05 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 25 Jul 2012 23:10:55 +0000 (01:10 +0200)
Found-by: Tanami Ohad
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/utils.c

index caa8c4b..fa3b962 100644 (file)
@@ -680,11 +680,15 @@ static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
         --st->probe_packets;
 
         if (pkt) {
-            pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
+            uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
+            if(!new_buf)
+                goto no_packet;
+            pd->buf = new_buf;
             memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
             pd->buf_size += pkt->size;
             memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
         } else {
+no_packet:
             st->probe_packets = 0;
         }