]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flacdec.c
movenc: Keep track of the allocated size for the cluster array
[ffmpeg] / libavformat / flacdec.c
index f481c10cfa0484f52d66abd8a04713a5a03606c5..9737095bbb199e6d00877842f98e9f79774c4fb5 100644 (file)
 static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
 {
     const CodecMime *mime = ff_id3v2_mime_tags;
-    enum  CodecID      id = CODEC_ID_NONE;
-    uint8_t mimetype[64], *desc = NULL, *data = NULL;
+    enum  AVCodecID      id = AV_CODEC_ID_NONE;
+    AVBufferRef *data = NULL;
+    uint8_t mimetype[64], *desc = NULL;
     AVIOContext *pb = NULL;
     AVStream *st;
     int type, width, height;
     int len, ret = 0;
 
-    st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
-
     pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL);
     if (!pb)
         return AVERROR(ENOMEM);
@@ -50,8 +47,11 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
     type      = avio_rb32(pb);
     if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
         av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type);
-        ret = AVERROR_INVALIDDATA;
-        goto fail;
+        if (s->error_recognition & AV_EF_EXPLODE) {
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
+        }
+        type = 0;
     }
 
     /* picture mimetype */
@@ -60,22 +60,24 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
         avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) {
         av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached "
                "picture.\n");
-        ret = AVERROR_INVALIDDATA;
+        if (s->error_recognition & AV_EF_EXPLODE)
+            ret = AVERROR_INVALIDDATA;
         goto fail;
     }
     mimetype[len] = 0;
 
-    while (mime->id != CODEC_ID_NONE) {
+    while (mime->id != AV_CODEC_ID_NONE) {
         if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
             id = mime->id;
             break;
         }
         mime++;
     }
-    if (id == CODEC_ID_NONE) {
+    if (id == AV_CODEC_ID_NONE) {
         av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
                mimetype);
-        ret = AVERROR_INVALIDDATA;
+        if (s->error_recognition & AV_EF_EXPLODE)
+            ret = AVERROR_INVALIDDATA;
         goto fail;
     }
 
@@ -88,7 +90,9 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
         }
 
         if (avio_read(pb, desc, len) != len) {
-            ret = AVERROR(EIO);
+            av_log(s, AV_LOG_ERROR, "Error reading attached picture description.\n");
+            if (s->error_recognition & AV_EF_EXPLODE)
+                ret = AVERROR(EIO);
             goto fail;
         }
         desc[len] = 0;
@@ -102,22 +106,32 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
     /* picture data */
     len = avio_rb32(pb);
     if (len <= 0) {
-        ret = AVERROR_INVALIDDATA;
+        av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
+        if (s->error_recognition & AV_EF_EXPLODE)
+            ret = AVERROR_INVALIDDATA;
         goto fail;
     }
-    if (!(data = av_malloc(len))) {
+    if (!(data = av_buffer_alloc(len))) {
         ret = AVERROR(ENOMEM);
         goto fail;
     }
-    if (avio_read(pb, data, len) != len) {
-        ret = AVERROR(EIO);
+    if (avio_read(pb, data->data, len) != len) {
+        av_log(s, AV_LOG_ERROR, "Error reading attached picture data.\n");
+        if (s->error_recognition & AV_EF_EXPLODE)
+            ret = AVERROR(EIO);
+        goto fail;
+    }
+
+    st = avformat_new_stream(s, NULL);
+    if (!st) {
+        ret = AVERROR(ENOMEM);
         goto fail;
     }
 
     av_init_packet(&st->attached_pic);
-    st->attached_pic.data         = data;
+    st->attached_pic.buf          = data;
+    st->attached_pic.data         = data->data;
     st->attached_pic.size         = len;
-    st->attached_pic.destruct     = av_destruct_packet;
     st->attached_pic.stream_index = st->index;
     st->attached_pic.flags       |= AV_PKT_FLAG_KEY;
 
@@ -135,8 +149,8 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
     return 0;
 
 fail:
+    av_buffer_unref(&data);
     av_freep(&desc);
-    av_freep(&data);
     av_freep(&pb);
     return ret;
 
@@ -151,7 +165,7 @@ static int flac_read_header(AVFormatContext *s)
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id = CODEC_ID_FLAC;
+    st->codec->codec_id = AV_CODEC_ID_FLAC;
     st->need_parsing = AVSTREAM_PARSE_FULL;
     /* the parameters will be extracted from the compressed bitstream */
 
@@ -265,11 +279,9 @@ static int flac_read_header(AVFormatContext *s)
 
 static int flac_probe(AVProbeData *p)
 {
-    uint8_t *bufptr = p->buf;
-    uint8_t *end    = p->buf + p->buf_size;
-
-    if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
-    else                                            return AVPROBE_SCORE_MAX/2;
+    if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
+        return 0;
+    return AVPROBE_SCORE_EXTENSION;
 }
 
 AVInputFormat ff_flac_demuxer = {
@@ -280,5 +292,5 @@ AVInputFormat ff_flac_demuxer = {
     .read_packet    = ff_raw_read_partial_packet,
     .flags          = AVFMT_GENERIC_INDEX,
     .extensions     = "flac",
-    .raw_codec_id   = CODEC_ID_FLAC,
+    .raw_codec_id   = AV_CODEC_ID_FLAC,
 };