h264: reset data partitioning at the beginning of each decode call
authorAnton Khirnov <anton@khirnov.net>
Thu, 28 Nov 2013 09:54:35 +0000 (10:54 +0100)
committerReinhard Tartler <siretart@tauware.de>
Sun, 1 Jun 2014 00:05:19 +0000 (20:05 -0400)
Prevents using GetBitContexts with data from previous calls.

Fixes access to freed memory.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC:libav-stable@libav.org

libavcodec/h264.c

index 1c2f23a..bca9bda 100644 (file)
@@ -4017,6 +4017,13 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
             }
             break;
         case NAL_DPA:
+            if (s->flags2 & CODEC_FLAG2_CHUNKS) {
+                av_log(h->s.avctx, AV_LOG_ERROR,
+                       "Decoding in chunks is not supported for "
+                       "partitioned slices.\n");
+                return AVERROR(ENOSYS);
+            }
+
             init_get_bits(&hx->s.gb, ptr, bit_length);
             hx->intra_gb_ptr=
             hx->inter_gb_ptr= NULL;
@@ -4170,6 +4177,9 @@ static int decode_frame(AVCodecContext *avctx,
 
     s->flags= avctx->flags;
     s->flags2= avctx->flags2;
+    /* reset data partitioning here, to ensure GetBitContexts from previous
+     * packets do not get used. */
+    s->data_partitioning = 0;
 
    /* end of stream, output what is still in the buffers */
  out: