Merge commit '8d4dd55c37b14ecea596f3477b35bf6c20688d8b'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 20 Sep 2012 11:30:44 +0000 (13:30 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 20 Sep 2012 11:32:43 +0000 (13:32 +0200)
* commit '8d4dd55c37b14ecea596f3477b35bf6c20688d8b':
  matroskadec: refactor matroska_decode_buffer

Conflicts:
libavformat/matroskadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/matroskadec.c

@@@ -1056,12 -994,22 +1056,27 @@@ static int matroska_decode_buffer(uint8
          return -1;
  
      switch (encodings[0].compression.algo) {
-     case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
-         if (encodings[0].compression.settings.size && !encodings[0].compression.settings.data) {
+     case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP: {
+         int header_size = encodings[0].compression.settings.size;
+         uint8_t *header = encodings[0].compression.settings.data;
++        if (header_size && !header) {
 +            av_log(0, AV_LOG_ERROR, "Compression size but no data in headerstrip\n");
 +            return -1;
 +        }
-         return encodings[0].compression.settings.size;
++
+         if (!header_size)
+             return 0;
+         pkt_size = isize + header_size;
+         pkt_data = av_malloc(pkt_size);
+         if (!pkt_data)
+             return AVERROR(ENOMEM);
+         memcpy(pkt_data, header, header_size);
+         memcpy(pkt_data + header_size, data, isize);
+         break;
+     }
      case MATROSKA_TRACK_ENCODING_COMP_LZO:
          do {
              olen = pkt_size *= 3;
@@@ -2079,15 -1924,18 +2088,13 @@@ static int matroska_parse_block(Matrosk
                  }
              } else {
                  MatroskaTrackEncoding *encodings = track->encodings.elem;
-                 int offset = 0;
 -                int pkt_size = lace_size[n];
 +                uint32_t pkt_size = lace_size[n];
                  uint8_t *pkt_data = data;
  
 -                if (pkt_size > size) {
 -                    av_log(matroska->ctx, AV_LOG_ERROR, "Invalid packet size\n");
 -                    break;
 -                }
 -
                  if (encodings && encodings->scope & 1) {
-                     offset = matroska_decode_buffer(&pkt_data,&pkt_size, track);
-                     if (offset < 0)
-                         continue;
-                     av_assert0(offset + pkt_size >= pkt_size);
+                     res = matroska_decode_buffer(&pkt_data, &pkt_size, track);
+                     if (res < 0)
+                         break;
                  }
  
                  pkt = av_mallocz(sizeof(AVPacket));