]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/ape.c
build: Make the ISMV muxer select the MOV muxer
[ffmpeg] / libavformat / ape.c
index 8145db3a767c638e26d2901c929ac4a3d6bf30ff..d67e684167b40635cac8568074b8f8a70e620b6b 100644 (file)
@@ -312,12 +312,6 @@ static int ape_read_header(AVFormatContext * s)
 
     ape_dumpinfo(s, ape);
 
-    /* try to read APE tags */
-    if (pb->seekable) {
-        ff_ape_parse_tag(s);
-        avio_seek(pb, 0, SEEK_SET);
-    }
-
     av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %"PRIu16"\n",
            ape->fileversion / 1000, (ape->fileversion % 1000) / 10,
            ape->compressiontype);
@@ -330,12 +324,11 @@ static int ape_read_header(AVFormatContext * s)
     total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
 
     st->codec->codec_type      = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id        = CODEC_ID_APE;
+    st->codec->codec_id        = AV_CODEC_ID_APE;
     st->codec->codec_tag       = MKTAG('A', 'P', 'E', ' ');
     st->codec->channels        = ape->channels;
     st->codec->sample_rate     = ape->samplerate;
     st->codec->bits_per_coded_sample = ape->bps;
-    st->codec->frame_size      = MAC_SUBFRAME_SIZE;
 
     st->nb_frames = ape->totalframes;
     st->start_time = 0;
@@ -355,6 +348,12 @@ static int ape_read_header(AVFormatContext * s)
         pts += ape->blocksperframe / MAC_SUBFRAME_SIZE;
     }
 
+    /* try to read APE tags */
+    if (pb->seekable) {
+        ff_ape_parse_tag(s);
+        avio_seek(pb, 0, SEEK_SET);
+    }
+
     return 0;
 }
 
@@ -379,6 +378,14 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
     else
         nblocks = ape->blocksperframe;
 
+    if (ape->frames[ape->currentframe].size <= 0 ||
+        ape->frames[ape->currentframe].size > INT_MAX - extra_size) {
+        av_log(s, AV_LOG_ERROR, "invalid packet size: %d\n",
+               ape->frames[ape->currentframe].size);
+        ape->currentframe++;
+        return AVERROR(EIO);
+    }
+
     if (av_new_packet(pkt,  ape->frames[ape->currentframe].size + extra_size) < 0)
         return AVERROR(ENOMEM);
 
@@ -431,5 +438,5 @@ AVInputFormat ff_ape_demuxer = {
     .read_packet    = ape_read_packet,
     .read_close     = ape_read_close,
     .read_seek      = ape_read_seek,
-    .extensions = "ape,apl,mac"
+    .extensions     = "ape,apl,mac",
 };