[FFmpeg-cvslog] flacdec: be less strict when parsing attached pictures.

Anton Khirnov git at videolan.org
Sun Jul 8 22:38:55 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Jul  6 22:30:17 2012 +0200| [b7d3a9a0153bc59cc43b753f0119f36da2b30b1a] | committer: Anton Khirnov

flacdec: be less strict when parsing attached pictures.

Only return an error if memory allocation fails or error recognition is
set to explode. Otherwise just print an error message and continue
reading the file.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b7d3a9a0153bc59cc43b753f0119f36da2b30b1a
---

 libavformat/flacdec.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 0be60a4..abb36d9 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -46,8 +46,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 */
@@ -56,7 +59,8 @@ 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;
@@ -71,7 +75,8 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
     if (id == 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;
     }
 
@@ -84,7 +89,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;
@@ -98,7 +105,9 @@ 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))) {
@@ -106,7 +115,9 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
         goto fail;
     }
     if (avio_read(pb, data, len) != len) {
-        ret = AVERROR(EIO);
+        av_log(s, AV_LOG_ERROR, "Error reading attached picture data.\n");
+        if (s->error_recognition & AV_EF_EXPLODE)
+            ret = AVERROR(EIO);
         goto fail;
     }
 



More information about the ffmpeg-cvslog mailing list