]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/matroskadec.c
nutdec: check chapter creation in decode_info_header
[ffmpeg] / libavformat / matroskadec.c
index d869e5381e5b66ea5d202f30ef823ede03c45f13..98efc7c03439ab8035b85c3e1caa90e712a15647 100644 (file)
@@ -2080,12 +2080,15 @@ static int matroska_read_header(AVFormatContext *s)
     matroska->cues_parsing_deferred = 1;
 
     /* First read the EBML header. */
-    if (ebml_parse(matroska, ebml_syntax, &ebml) ||
-        ebml.version         > EBML_VERSION      ||
+    if (ebml_parse(matroska, ebml_syntax, &ebml) || !ebml.doctype) {
+        av_log(matroska->ctx, AV_LOG_ERROR, "EBML header parsing failed\n");
+        ebml_free(ebml_syntax, &ebml);
+        return AVERROR_INVALIDDATA;
+    }
+    if (ebml.version         > EBML_VERSION      ||
         ebml.max_size        > sizeof(uint64_t)  ||
         ebml.id_length       > sizeof(uint32_t)  ||
-        ebml.doctype_version > 3                 ||
-        !ebml.doctype) {
+        ebml.doctype_version > 3) {
         av_log(matroska->ctx, AV_LOG_ERROR,
                "EBML header using unsupported features\n"
                "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
@@ -2159,6 +2162,8 @@ static int matroska_read_header(AVFormatContext *s)
                 }
             }
 
+            attachments[j].stream = st;
+
             if (st->codec->codec_id != AV_CODEC_ID_NONE) {
                 st->disposition      |= AV_DISPOSITION_ATTACHED_PIC;
                 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -2174,7 +2179,7 @@ static int matroska_read_header(AVFormatContext *s)
                 if (ff_alloc_extradata(st->codec, attachments[j].bin.size))
                     break;
                 memcpy(st->codec->extradata, attachments[j].bin.data,
-                    attachments[j].bin.size);
+                       attachments[j].bin.size);
 
                 for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) {
                     if (!strncmp(ff_mkv_mime_tags[i].str, attachments[j].mime,
@@ -2183,7 +2188,6 @@ static int matroska_read_header(AVFormatContext *s)
                         break;
                     }
                 }
-                attachments[j].stream = st;
             }
         }
     }