wmapro: make sure there is room to store the current packet
authorLuca Barbato <lu_zero@gentoo.org>
Fri, 28 Jun 2013 02:03:47 +0000 (04:03 +0200)
committerReinhard Tartler <siretart@tauware.de>
Sat, 6 Jul 2013 08:06:11 +0000 (10:06 +0200)
Prevent horrid and hard to trace struct overwrite.

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
(cherry picked from commit e30b068ef79f604ff439418da07f7e2efd01d4ea)

Signed-off-by: Reinhard Tartler <siretart@tauware.de>
libavcodec/wmaprodec.c

index 1b7797c9f2aa69b60e020b845266052a4190ba8b..cc8df9b900845e6782fb7af8ad56a05c76c407a3 100644 (file)
@@ -1466,6 +1466,14 @@ static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
         return;
     }
 
+    if (len > put_bits_left(&s->pb)) {
+        av_log(s->avctx, AV_LOG_ERROR,
+               "Cannot append %d bits, only %d bits available.\n",
+               len, put_bits_left(&s->pb));
+        s->packet_loss = 1;
+        return;
+    }
+
     s->num_saved_bits += len;
     if (!append) {
         avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),