[FFmpeg-cvslog] swfdec: do better validation of tag length

Justin Ruggles git at videolan.org
Sun Jul 21 03:43:34 CEST 2013


ffmpeg | branch: release/1.0 | Justin Ruggles <justin.ruggles at gmail.com> | Mon Dec 10 12:44:09 2012 -0500| [d46713cc7e7dfd88b813078a71ed1c29e42011ca] | committer: Michael Niedermayer

swfdec: do better validation of tag length

Avoids trying to read a packet with 0 or negative size.
Avoids a potential infinite loop due to seeking backwards.

Partially based on a patch by Michael Niedermayer.
(cherry picked from commit e70c5b034c4787377e82cab2d5565486baec0c2a)

Conflicts:

	libavformat/swfdec.c

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

 libavformat/swfdec.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index 9a8ef53..ee1b596 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -154,7 +154,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
         if (tag < 0)
             return tag;
         if (len < 0) {
-            av_log(s, AV_LOG_ERROR, "len %d is invalid\n", len);
+            av_log(s, AV_LOG_ERROR, "invalid tag length: %d\n", len);
             return AVERROR_INVALIDDATA;
         }
         if (tag == TAG_VIDEOSTREAM) {
@@ -212,7 +212,10 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                 st = s->streams[i];
                 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) {
                     frame = avio_rl16(pb);
-                    if ((res = av_get_packet(pb, pkt, len-2)) < 0)
+                    len -= 2;
+                    if (len <= 0)
+                        goto skip;
+                    if ((res = av_get_packet(pb, pkt, len)) < 0)
                         return res;
                     pkt->pos = pos;
                     pkt->pts = frame;
@@ -226,9 +229,14 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) {
             if (st->codec->codec_id == AV_CODEC_ID_MP3) {
                 avio_skip(pb, 4);
-                if ((res = av_get_packet(pb, pkt, len-4)) < 0)
+                len -= 4;
+                if (len <= 0)
+                    goto skip;
+                if ((res = av_get_packet(pb, pkt, len)) < 0)
                     return res;
             } else { // ADPCM, PCM
+                if (len <= 0)
+                    goto skip;
                 if ((res = av_get_packet(pb, pkt, len)) < 0)
                     return res;
             }
@@ -254,7 +262,10 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
                 st = vst;
             }
             avio_rl16(pb); /* BITMAP_ID */
-            if ((res = av_new_packet(pkt, len-2)) < 0)
+            len -= 2;
+            if (len < 4)
+                goto skip;
+            if ((res = av_new_packet(pkt, len)) < 0)
                 return res;
             avio_read(pb, pkt->data, 4);
             if (AV_RB32(pkt->data) == 0xffd8ffd9 ||
@@ -271,6 +282,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
             return pkt->size;
         }
     skip:
+        len = FFMAX(0, len);
         avio_skip(pb, len);
     }
 }



More information about the ffmpeg-cvslog mailing list